show | version | enable^checker |
---|---|---|
step |
1.0 |
true |
- 开源的python 赶上了好时代
- 并且有非常强大的运算能力
- 还有很多人帮助他
- 得道多助
- 失道寡助
- 这就是python的累积
- 就像加法累积成乘法
- 乘法累积成乘方一样
- 积小胜为大胜
- 积跬步以至千里
- 积量变而质变
- python
- 终日都在向前进步
- 乘方的逆运算是什么呢?
- 开方
- 开方怎么做的呢?🤪
- 平方是
$2$ 次方 - 开方是
$0.5$ 次方
- 对
$-1$ 开方会如何?
- 没有报错?!
- 虽然不理解
- 但生活要继续
- 看看立方
- 三次方简称立方运算
- 求三次立方根是他的逆运算
-
$2$ 的$3$ 次方是$8$ -
$8$ 的立方根是$2$ - 如果是求倒数可以做么?
-
$-1$ 次方就是倒数 -
$-2$ 次方就是平方倒数 -
$-0.5$ 次方就是平方根倒数
- 三分之一和九分之一并不精确
- 有什么办法吗?
- 一种是控制分母大小
- 另一种是分数当做底数
- 哪个好?为什么?
- 乘方和开方运算都是指数运算
- 指数运算有没有逆运算?
- python 能做吗?
-
$log_24$ = 2 - log 以
$2$ 为底$4$ 的对数$= 2$
- 结果是一个浮点型变量
- 两个参数都需要写么
- 猜测第二个参数默认为 e
$log(x) = log_e(x)=ln(x)$
- 查询帮助手册
- 验证成功
- 对数运算经常出现以 10 为底
-
$log10$ 以$10$ 为底 -
$log2$ 以$2$ 为底
$log_x(y) = lg2/lg3 = ln2/ln3$
- 看起来分数是先被转化为浮点数
- 然后进行处理的
- 结果也是浮点数
- 这些函数的究竟是怎么实现的呢?
- 代码可以在cpython中找到
- https://github.com/python/cpython/blob/23c9febdc6620c2ec5b6119d9016a8c92c25f350/Modules/mathmodule.c
- 我理解cpython的意思就是
- 用c写的python解释器
- 这个math包里面的东西都是用c写的
- 因为效率高
- 上来之后就是一段灵魂注释
- Tim Peter留给我们的754的灵魂
Here are some comments from Tim Peters, extracted from the discussion attached to http://bugs.python.org/issue1640. They describe the general aims of the math module with respect to special values, IEEE-754 floating-point exceptions, and Python exceptions. These are the "spirit of 754" rules:
- If the mathematical result is a real number, but of magnitude too large to approximate by a machine float, overflow is signaled and the result is an infinity (with the appropriate sign).
- If the mathematical result is a real number, but of magnitude too small to approximate by a machine float, underflow is signaled and the result is a zero (with the appropriate sign).
- At a singularity (a value x such that the limit of f(y) as y approaches x exists and is an infinity), "divide by zero" is signaled and the result is an infinity (with the appropriate sign). This is complicated a little by that the left-side and right-side limits may not be the same; e.g., 1/x approaches +inf or -inf as x approaches 0 from the positive or negative directions. In that specific case, the sign of the zero determines the result of 1/0.
- At a point where a function has no defined result in the extended reals (i.e., the reals plus an infinity or two), invalid operation is signaled and a NaN is returned. And these are what Python has historically /tried/ to do (but not always successfully, as platform libm behavior varies a lot): For #1, raise OverflowError. For #2, return a zero (with the appropriate sign if that happens by accident ;-)). For #3 and #4, raise ValueError. It may have made sense to raise Python's ZeroDivisionError in #3, but historically that's only been raised for division by zero and mod by zero.
- 你想研究算法吗?
- 平方是怎么开的
- 对数是怎么算的
- 源码就在那里...
- 不过话说回来
- 这句经典口号说的不就是python类库很强大
- 一调用就行了
- 不用管细节么?
- 感谢这些算法大神
- 平方运算的逆运算是开平方
- 指数为
$2$ ,平方 - 指数为
$0.5$ ,开平方 - 指数为
$-1$ ,取倒数
- 指数为
- 平方和开平方都属于指数运算
- 指数运算的逆运算是对数运算
- 不过有个问题
-
$-1$ 的平方根好像是一个乱码?
-
- 如何理解?🤔
- 下次再说 👋