Skip to content

Instantly share code, notes, and snippets.

@mgttt
Last active July 7, 2023 15:29
Show Gist options
  • Save mgttt/85985a1a9573918f59baf106a39e2d5f to your computer and use it in GitHub Desktop.
Save mgttt/85985a1a9573918f59baf106a39e2d5f to your computer and use it in GitHub Desktop.
interesting maths with python
approximation function for natural logarithm
# ln=(x,a=2**32)=>a*x**(1/a)-a
#ln=lambda x,a=1<<32:a*x**(1/a)-a
ln=lambda x,a=1<<32:a*(x**(1/a)-1)

>>> numpy.log(400) - ln(400)
-6.776018235399306e-08

经典(牛顿引力) $F = G \frac{m_1 m_2}{r^2}$

广义相对论 $G_{\mu\nu} = \frac{8 \pi G}{c^4} T_{\mu\nu}$ $G_{\mu\nu}$ 爱因斯坦张量 $T_{\mu\nu}$ 能量-动量张量 G 是牛顿的引力常数 c 是光速


$$T = \begin{pmatrix} T_{00} & T_{01} & T_{02} & T_{03} \\\ T_{10} & T_{11} & T_{12} & T_{13} \\\ T_{20} & T_{21} & T_{22} & T_{23} \\\ T_{30} & T_{31} & T_{32} & T_{33} \end{pmatrix}$$
T = \begin{pmatrix}
T_{00} & T_{01} & T_{02} & T_{03} \\
T_{10} & T_{11} & T_{12} & T_{13} \\
T_{20} & T_{21} & T_{22} & T_{23} \\
T_{30} & T_{31} & T_{32} & T_{33}
\end{pmatrix}

$$ \begin{aligned} & \phi(x,y) = \phi \left(\sum_{i=1}^n x_ie_i, \sum_{j=1}^n y_je_j \right) = \sum_{i=1}^n \sum_{j=1}^n x_i y_j \phi(e_i, e_j) = \\ & (x_1, \ldots, x_n) \left( \begin{array}{ccc} \phi(e_1, e_1) & \cdots & \phi(e_1, e_n) \\ \vdots & \ddots & \vdots \\ \phi(e_n, e_1) & \cdots & \phi(e_n, e_n) \end{array} \right) \left( \begin{array}{c} y_1 \\ \vdots \\ y_n \end{array} \right) \end{aligned} $$

$$
\begin{aligned}
  & \phi(x,y) = \phi \left(\sum_{i=1}^n x_ie_i, \sum_{j=1}^n y_je_j \right)
  = \sum_{i=1}^n \sum_{j=1}^n x_i y_j \phi(e_i, e_j) = \\
  & (x_1, \ldots, x_n) \left( \begin{array}{ccc}
      \phi(e_1, e_1) & \cdots & \phi(e_1, e_n) \\
      \vdots & \ddots & \vdots \\
      \phi(e_n, e_1) & \cdots & \phi(e_n, e_n)
    \end{array} \right)
  \left( \begin{array}{c}
      y_1 \\
      \vdots \\
      y_n
    \end{array} \right)
\end{aligned}
$$
@mgttt
Copy link
Author

mgttt commented Jul 1, 2023

R_{\mu\nu} - \frac{1}{2}Rg_{\mu\nu} + \Lambda g_{\mu\nu} = \frac{8\pi G}{c^4} T_{\mu\nu}
$R_{\mu\nu} - \frac{1}{2}Rg_{\mu\nu} + \Lambda g_{\mu\nu} = \frac{8\pi G}{c^4} T_{\mu\nu}$
$R_{\mu\nu}$ 是里奇张量(Ricci tensor);
$R$ 是标量曲率(scalar curvature);
$g_{\mu\nu}$ 是度规张量(metric tensor);
$\Lambda$ 是宇宙学常数(cosmological constant);
$G$ 是引力常数;
$c$ 是光速;
$T_{\mu\nu}$ 是能动张量(energy-momentum tensor)

@mgttt
Copy link
Author

mgttt commented Jul 1, 2023

在广义相对论中,我们引入度规(metric)来描述时空的几何结构。度规是一个二阶对称张量 $g_{\mu\nu}$,其中 $\mu, \nu$ 是时空的索引。度规在每个时空点上给出了时空的度量,它描述了时空中的间隔和距离。

度规可以用以下形式表示:
ds^2 = g_{\mu\nu} dx^\mu dx^\nu
$ds^2 = g_{\mu\nu} dx^\mu dx^\nu$

其中 $ds$ 是时空间隔元素,$dx^\mu$ 是坐标的微小变化。在一般的曲线坐标系中,度规元素 $g_{\mu\nu}$ 是坐标的函数。不同坐标系下的度规元素可以通过坐标变换进行转换。

度规的索引可以采用爱因斯坦求和约定。根据这个约定,当一个指标在一个项中出现了两次,那么我们默认进行求和。因此,度规的元素可以用下标表示为 $g_{\mu\nu}$,而指标 $\mu$$\nu$ 可以取 $0, 1, 2, 3$ 的值。

度规是广义相对论中最基本的概念之一,它描述了时空的几何性质。通过度规,我们可以计算时空中的线元、弯曲度量和时空间隔等。在爱因斯坦场方程中,度规的选择和性质直接影响着引力场的描述和时空的演化。

@mgttt
Copy link
Author

mgttt commented Jul 1, 2023

黎曼函数
$$\zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s}$$
\zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s}

@mgttt
Copy link
Author

mgttt commented Jul 2, 2023

$${\begin{aligned}z&=x+iy=|z|(\cos \varphi +i\sin \varphi )=re^{i\varphi },\\{\bar {z}}&=x-iy=|z|(\cos \varphi -i\sin \varphi )=re^{-i\varphi },\end{aligned}}$$

@mgttt
Copy link
Author

mgttt commented Jul 2, 2023

equivalence of euler formula and matrix transform

from sympy import symbols, Matrix, acos, cos, sin, I, exp, re, im

a2v = lambda *a:Matrix(a)

norm = lambda V:V.norm()

# i.e. Z.dot(R) 
dot_product = lambda Z,R:Matrix.dot(Z,R)

# quick angle (not checking zero v yet)
angle_func = lambda Z,R:acos(dot_product(Z,R)/(norm(Z)*norm(R)))

# the transformation matrix
def find_M1(Z,R):
  angle = angle_func(Z,R)
  return Matrix([[cos(angle), -sin(angle)], [sin(angle), cos(angle)]])

def find_M2(Z,R):
  angle = angle_func(Z,R)
  complex_angle = angle * I
  exp_angle = exp(complex_angle)
  return Matrix([[ re(exp_angle), -im(exp_angle)],[im(exp_angle), re(exp_angle)]])

v1 = a2v(1,2)
v2 = a2v(2,3)
assert find_M1(v1,v2) == find_M2(v1,v2)

@mgttt
Copy link
Author

mgttt commented Jul 7, 2023

Fourier Transform: F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-i\omega t} dt
$$F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-i\omega t} dt$$
Discrete Fourier Transform (DFT): X[k] = \sum_{n=0}^{N-1} x[n] e^{-i \frac{2\pi}{N} nk}
$$X[k] = \sum_{n=0}^{N-1} x[n] e^{-i \frac{2\pi}{N} nk}$$

@mgttt
Copy link
Author

mgttt commented Jul 7, 2023

Laplace Transform 拉普拉斯变换 F(s) = \mathcal{L}{f(t)} = \int_{0}^{\infty} f(t) e^{-st} dt
$$F(s) = \mathcal{L}{f(t)} = \int_{0}^{\infty} f(t) e^{-st} dt$$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment