# Quicklisp, 2

Euler problem 13

.

To run the following code, you have to install the Quicklisp library manager by following the steps in my blog post titled cmu-infix.

(ql:quickload "str")

(defun file-get-contents (filename)
(with-open-file (stream filename)
(let ((contents (make-string
(file-length stream))))
contents)))

(defun file-get-lines (filename)
(with-open-file (stream filename)
(loop :for line = (read-line stream nil)
:while line
:collect line)))

(file-get-lines #P"n.txt")

(defun string-to-list (the-string)
(loop :for char :across the-string
:collect char))

(defun char-to-integer-list (char-list)
(mapcar #'digit-char-p char-list))

(let ((the-list (file-get-contents #P"n.txt")))
(subseq
(prin1-to-string
(reduce
#'+
(mapcar
#'parse-integer
(butlast (str:split #\newline the-list)))))
0 10))


— Me@2023-05-26 12:16:50 PM

.

.

# Ex 1.29 A particle of mass m slides off a horizontal cylinder, 1.1

Structure and Interpretation of Classical Mechanics

.

A particle of mass $m$ slides off a horizontal cylinder of radius $R$ in a uniform gravitational field with acceleration $g$. If the particle starts close to the top of the cylinder with zero initial speed, with what angular velocity does it leave the cylinder?

~~~

Along the tangential direction,

$\displaystyle{m \frac{dv}{dt} = m g \sin \theta - f_a - f}$

Assuming there is only air friction,

$\displaystyle{m \frac{dv}{dt} = m g \sin \theta - f_a}$

.

If the air resistance $\displaystyle{f_a}$ equals $\displaystyle{\frac{\beta m v^2}{2 R}}$,

$\displaystyle{ m \frac{dv}{dt} = m g \sin \theta - \frac{\beta m v^2}{2 R} }$

.

Along the normal direction,

\displaystyle{\begin{aligned} F_{\text{net}} &= F_C \\ m g \cos \theta - F_R &= \frac{m v^2}{R} \\ \end{aligned}},

where $\displaystyle{F_R}$ is the normal reaction force.

So

\displaystyle{\begin{aligned} m R \frac{d \dot \theta}{dt} &= m g \sin \theta - \frac{\beta}{2} \left( m g \cos \theta - F_R \right) \\ R \ddot \theta &= g \sin \theta - \frac{\beta}{2} \left( g \cos \theta - F_R \right) \\ \end{aligned}}

This equation is not useful yet, because $\displaystyle{F_R(\theta(t))}$ is still not known. So we keep using the original equation:

\displaystyle{\begin{aligned} m \frac{dv}{dt} &= m g \sin \theta - \frac{\beta m v^2}{2 R} \\ R \frac{d^2 \theta}{dt^2} &= g \sin \theta - \frac{\beta R \dot \theta^2}{2} \\ \end{aligned}}

Let

\displaystyle{\begin{aligned} u &= \dot \theta^2 \\ \end{aligned}}

— Me@2023-05-23 11:02:25 AM

.

.

# Not a number

Infinity is not a number.

Infinity is a process of ever increasing.

An ever-increasing process cannot be assigned a number.

.

At a particular time, the process has a particular number such as density.

But the whole process itself cannot be assigned a number.

— Me@2016-04-24 07:10:28 AM

.

.

# 原因非理由

— Me@2016-03-31 08:35:43 PM

.

.

# VirtualBox Start

In KDE, when a Virtualbox virtual machine is turned on, sometimes, both the guest OS and the host OS would capture the Super key at the same time. In order to avoid that, use the following steps:

1. Right-click the VirtualBox title bar

2. Choose:

More Actions
$\to$ Special Window Settings
$\to$ Ignore Global Shortcuts (in Appearance and Fixes)
$\to$ Force $\to$ Yes

— Me@2023-05-17 07:52:55 PM

.

.

# 3.4 Electric fields and potentials of point charges, 2

A First Course in String Theory

.

(b) Show that with $d$ spatial dimensions, the potential $\Phi$ due to a point charge $q$ is given by

$\displaystyle{\Phi(r) = \frac{\Gamma \left( \frac{d}{2} - 1 \right)}{4 \pi^{d/2}} \frac{q}{r^{d-2}}}$

~~~

Eq. (3.74):

$\displaystyle{E(r) = \frac{\Gamma\left( \frac{d}{2} \right)}{2 \pi^{\frac{d}{2}}} \frac{q}{r^{d-1}}}$

.

\displaystyle{\begin{aligned} E(r) &= -\frac{d\Phi(r)}{dr} \\ \\ \int_r^{\infty} d\Phi &= - \frac{\Gamma\left( \frac{d}{2} \right)}{2 \pi^{\frac{d}{2}}} q \int_r^{\infty} r^{-d+1} dr \\ \\ \Phi(\infty) - \Phi(r) &= \frac{\Gamma\left( \frac{d}{2} \right)}{4 \pi^{\frac{d}{2}}} \frac{q}{\frac{d}{2}-1} \left[\frac{1}{r^{d-2}} \right]_r^{\infty} \\ \\ \Gamma (z) &= \frac{\Gamma (z+1)}{z} \\ \\ \Phi(r) &= \frac{\Gamma\left( \frac{d}{2} - 1\right)}{4 \pi^{\frac{d}{2}}} \frac{q}{r^{d-2}} \\ \\ \end{aligned} }

— Me@2023-05-17 09:11:07 AM

.

.

# Random variable

Random variable $X$ represents a single-valued result of a random event. Its value is unknown to us, not because of our ignorance, but because of its non-existence. The value exists only after the happening of that random event.

Symbol $x$ represents a particular value of $X$. It is an existing value that can be substituted to $X$. We use symbol $x$ instead of a number because we have not yet known what that particular number is.

— Me@2016-04-08 05:24:45 PM

.

X ~ random variable

It is a variable due to the fact that the “identical” random process can result differently at different times.

.

x ~ a value of X

Since it is a particular value of X, it is not a variable. However, it may seem to be a variable because it may still be unknown to us.

.

Symbol $P(X)$ is meaningless because inside, it must be a statement (representing an event). Symbol $X$ is a random variable, not a statement.

Instead, “$X=x$” is a statement. So expression $P(X=x)$ is meaningful, such as

$P(X=x) = {\begin{cases}{\frac {1}{2}},&x=0,\\{\frac {1}{2}},&x=1,\\0,&x\notin \{0,1\} \end{cases}}$

.

From another point of view, $X$ is a noun phrase, such as “my monthly salary”, not a number. Symbol $x$ is a number, although maybe not known yet. That’s why whatever the formula, it contains no $X$‘s, but $x$‘s. For example,

$\cdots = {\begin{cases}{\frac {1}{2}},&x=0,\\{\frac {1}{2}},&x=1,\\0,&x\notin \{0,1\} \end{cases}}$

— Me@2016-05-04 06:32:24 PM

.

.

# NotesOrganization

"A real person has two reasons for doing anything...
a good reason and the real reason."

…

One today worths two tomorrows.

Do one thing well. Do exactly what a customer wants,
nothing more, nothing less.

You can't solve all the problems. You can't satisfy
all the people.

Constructive laziness is one of the cardinal virtues
of a master programmer.

"such a final theory must be concerned not with fields,
not even with spacetime, but rather with information
exchange among physical processes."

…

04[.]08[.]2003

A good scientist is a person with original ideas.
A good engineer is a person who makes a design
that works with as few original ideas as possible.
There are no prima donnas in engineering.
-- Freeman Dyson

"There are two kinds of researchers:
those that have implemented something and
those that have not. The latter will tell you that
there are 142 ways of doing things and that
there isn't consensus on which is best.
The former will simply tell you that 141 of them
don't work."

ResearchNotesOrganization


.

.

2023.05.14 Sunday ACHK

# 電腦革命

.

.

.

— Me@2023-03-10 11:00:16 AM

.

.

# Euler problem 12.2

primes :: [Integer]
primes = 2 : filter (null . tail . primeFactors) [3, 5 ..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
where
factor n (p : ps)
| p * p > n = [n]
| n mod p == 0 = p : factor (n div p) (p : ps)
| otherwise = factor n ps

groupFactors :: [Integer] -> [[Integer]]
groupFactors = gf []
where
gf acc lst
| null lst = reverse acc
| null acc = gf [[p,1]] ps
--
--
| otherwise = gf ([p,1]:acc) ps
where
ps = tail lst

nDiv :: Integer -> Integer
nDiv n = product (map ((1+) . head . tail)
(groupFactors (primeFactors n)))

fm :: Integer -> Integer -> Integer
fm m n
| triDiv n > m = n*(n+1) div 2
| otherwise = fm m (n+1)
where
triDiv n
| even n = nDiv (n div 2)*nDiv (n+1)
| otherwise = nDiv n*nDiv ((n+1) div 2)


λ> :set +s
λ> fm 500 1
76576500
(0.20 secs, 199,313,728 bytes)
λ> 

— Me@2023-05-04 09:51:19 AM

.

.