ときどきの雑記帖 RE* (新南口)
そらよりもとおいばしょ
にこたま
先週末にちょいと用事があって二子玉川まで出たのだけど 人出がすごくて閉口した。
2年前の今頃と比較しちゃあいけないんだろうけど、 あれだけ人が多いと(ぴー)も多くて以下略
K&R
K&Rとワインバーグ本(「ライト、ついてますか」とか)がいつの間にかKindle化されていた。というか共立出版、電子書籍に参入してたんだ。
— 愉快な生活送り太郎 (@hassyX) May 27, 2022
プログラミング言語C 第2版 ANSI規格準拠 https://t.co/i1WQxfVclr
ライト、ついてますか 問題発見の人間学 https://t.co/gXehHdfwUy
「ライト、ついてますか」は知ってたけど(買ってもいた)K&Rも出てたんだ。 まあ買うかどうかというと微妙ではあるけど。
比喩
膨張の果てに赤色巨星化し寿命を終えるCOBOL、巻き込まれないためには? | 日経クロステック(xTECH)
どういう意図でこういう表現をしたのかよくわからんのだけど 「超新星爆発」が起きるとかいう話?
鎌倉文学館
鎌倉文学館、来年4月から休館 大規模改修で2年間 | 鎌倉 | タウンニュース
バラの名所として知られる鎌倉文学館で5月10日、「バラまつり」が開幕した。 「鎌倉」や「静の舞」、「大姫」といった地元ゆかりの品種も含めた202種245株が、順次開花していく。 「今週末から20日頃までが最も咲き揃う時期」と同館。バラまつりは6月12日(土)まで。来年以降は休館のため、イベントも休止となる。
2年休館かあ。 久しぶりに行くかな。
MASTERキートン
浦沢直樹「MASTERキートン」「MASTERキートン Reマスター」電子版解禁 - コミックナタリー
浦沢直樹作品の電子化プロジェクト第4弾となる「MASTERキートン」「MASTERキートン Reマスター」が、本日5月30日に各電子書店で配信開始された。
ついにというかようやくというか。 とは言えパッと全巻大人買いするほどには余裕がないのだな😢
MASTERキートン 完全版 デジタルVer. (全12巻) Kindle版
-3**2
つづき。 今回はTcl。
Tcl
tcl/tclCompExpr.c at main · tcltk/tcl
/*
* When ParseExpr() builds the parse tree it must choose which operands to
* connect to which operators. This is done according to operator precedence.
* The greater an operator's precedence the greater claim it has to link to an
* available operand. The Precedence enumeration lists the precedence values
* used by Tcl expression operators, from lowest to highest claim. Each
* precedence level is commented with the operators that hold that precedence.
*/
enum Precedence {
PREC_END = 1, /* END */
PREC_START, /* START */
PREC_CLOSE_PAREN, /* ")" */
PREC_OPEN_PAREN, /* "(" */
PREC_COMMA, /* "," */
PREC_CONDITIONAL, /* "?", ":" */
PREC_OR, /* "||" */
PREC_AND, /* "&&" */
PREC_BIT_OR, /* "|" */
PREC_BIT_XOR, /* "^" */
PREC_BIT_AND, /* "&" */
PREC_EQUAL, /* "==", "!=", "eq", "ne", "in", "ni" */
PREC_COMPARE, /* "<", ">", "<=", ">=" */
PREC_SHIFT, /* "<<", ">>" */
PREC_ADD, /* "+", "-" */
PREC_MULT, /* "*", "/", "%" */
PREC_EXPON, /* "**" */
PREC_UNARY /* "+", "-", FUNCTION, "!", "~" */
};
計算式の構文解析は演算子優先順位法でやってる感じ。
Bash
色々検索していて見つけた。
bash - Why is the precedence of exponentiation lower than that of unary plus minus? - Stack Overflow
Question: Why do shells have this particular precedence order? I assume this is genealogical based ksh > bash > zsh. But still ..
Note: exponentiation is not part of POSIX
Note: other languages/interpreters exist with a similar precedence order such as bc, tcl
起源はとりあえずおいといて(ksh?)、 そこから「互換性」を保ち続けているということなんですかね。 一度そうしてしまったら後からは変えづらいだろうし。
Learning the Korn Shell という本によれば、kshにもべき乗演算子があったらしい。
その優先順位(の一部)はこんな感じ。
**Table 6-2. Arithmetic operators **
Operator | Meaning | Associativity |
---|---|---|
++ – | Increment and decrement, prefix and postfix | Left to right |
+ - ! ~ | Unary plus and minus; logical and bitwise negation | Right to left |
** | Exponentiation | [84] Right to left |
* / % | Multiplication, division, and remainder | Left to right |
+ - | Addition and subtraction | Left to right |
[84] ksh93m and newer. The ** operator is not in the C language.
ksh93/ksh: ksh 93u+m: current development of KornShell, based off the last stable AT&T release (93u+ 2012-08-01) を見るとなにかわかるだろうか?
Perl 5.36.0
perldelta - what is new for perl v5.36.0 - metacpan.org
変更内容をみるといくつか興味をひかれるものがあったけど
- regex sets are no longer considered experimental
- Variable length lookbehind is mostly no longer considered experimental
一番はこれかな(まだexperimentalだけど)。 iterating over multiple values at a time (experimental)
You can now iterate over multiple values at a time by specifying a list of lexicals within parentheses. For example,
for my ($key, $value) (%hash) { ... } for my ($left, $right, $gripping) (@moties) { ... }
Prior to perl v5.36, attempting to specify a list after for my was a syntax error.
This feature is currently experimental and will cause a warning of category experimental::for_list. For more detail see “Compound Statements” in perlsyn. See also “builtin::indexed” in this document, which is a handy companion to n-at-a-time foreach.
前者(ハッシュのkeyとvalueのペアを受け取る)は以前にも見た覚えがあるか。
ところで strawberry perlが5.32ベースからあがってないんですがそれは。
Leslie Lamport
これについてredditでも大いに盛り上がっていた。 “If people are trying to learn programming by being taught to code, well, they’re being taught writing by being taught how to type and that doesn’t make much sense” - Leslie Lamport : programming
IMO a better analogy would be “.. they’re being taught writing by being taught grammar and that doesn’t make much sense”.
Programmers are taught the basic syntax of programming but very little on overall program design and flow. How to write code that is maintainable, performant and scalable is not easy, not taught and, lets be honest, not even that valued in the industry. If it was appropriately valued there would be no ageism and experienced developers would be valued as developers instead of as technical managers.
Leslie Lamport (チューリング賞受賞、TLA+, Paxos開発者) インタビュー。
— 新山祐介 (Yusuke Shinyama) (@mootastic) May 19, 2022
「ほとんどのプログラマはただコードを書くだけで、アルゴリズムについて考えない。分散並行システムでそれをやったら、バグだらけになるのは目に見えている。プログラマは数学的に考える必要がある」https://t.co/QRqdQjq8qs
links
- Computing Expert Says Programmers Need More Math | Quanta Magazine
- I hate codegrepper. Unrelated snippets are somehow the first Google result. : programming
- jest mock buffer.from Code Example
- Neil Brown: How Your Mind Learns to Program : programming
Generating random points uniformly on a disk
円の内側の点をランダムで一様に生成するには、ランダムな極座標 (r, θ) に対する点を生成しても一様分布にならない。しかし、(√r, θ) からなる点を使うと一様分布になる。 https://t.co/BQE1da9ZCK
— 新山祐介 (Yusuke Shinyama) (@mootastic) May 26, 2022
意図してのものかわからないけど、単純に、(√r, θ)
としちゃいけないんじゃなかろうか。
というのも元ツイート
Basic fact all graphics coders should know:
— Keenan Crane (@keenanisalive) May 25, 2022
To uniformly sample points in a disk, you'd think you could just pick a random radius r ∈ [0,1] and a random angle θ ∈ [0,2π] to generate points r (cos θ, sin θ).
This doesn't work!
…But take the square root of r, and it does! 1/3 pic.twitter.com/iEgdf7fqCB
のようにrが1なら問題がない(たぶん)けど、 rが4とか10になると想定する円が小さくなってしまうような。
> R=4
> N=1000
>
> max(sqrt(runif(N, min=0, max=R)))
[1] 1.998111
以前自分が同じ問題にぶつかったときにお世話になった 円内に一様分布する乱数を生成する時は、俺、絶対忘れないよヤコビアンのこと - My Life as a Mock Quant にある式を使うと
> max(sqrt(2*runif(N, min=0, max=0.5*R^2)))
[1] 3.999537
> R=10
> max(sqrt(2*runif(N, min=0, max=0.5*R^2)))
[1] 9.990626
> max(sqrt(2*runif(N, min=0, max=R)))
[1] 4.471483
> max(sqrt(runif(N, min=0, max=R)))
[1] 3.159434
プロットするにはこう
theta <- runif(N, min=0, max=2*pi)
r <- sqrt(2*runif(N, min=0, max=R))
df <- data.frame(x=r*cos(theta), y=r*sin(theta))
ggplot(df, aes(x=x, y=y)) + geom_point(color="blue")
r <- sqrt(2*runif(N, min=0, max=0.5*R^2))
そのほか検索して見つかったのはこんな感じ(R、numpy)
self study - Generating random points uniformly on a disk - Cross Validated
runifcircle <- function(n, centre = c(0, 0), center = centre, radius = 1) {
#Check inputs
if (!missing(centre) && !missing(center)) {
if (sum((centre - center)^2) < 1e-15) {
warning("specify 'centre' or 'center' but not both") } else {
stop("Error: specify 'centre' or 'center' but not both") } }
if (radius < 0) { stop("Error: radius must be non-negative") }
#Create output matrix
OUT <- matrix(0, nrow = 2, ncol = n)
rownames(OUT) <- c('x', 'y')
#Generate uniform values on circle
r2 <- runif(n, min = 0, max = radius^2)
theta <- runif(n, min = 0, max = 2*pi)
OUT[1, ] <- center[1] + sqrt(r2)*cos(theta)
OUT[2, ] <- center[2] + sqrt(r2)*sin(theta)
OUT }
Generate Random Points over the Disk
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
np.random.seed(524)
U1 = np.random.uniform(size = 10000)
U2 = np.random.uniform(size = 10000)
r = 1
X = r * np.sqrt(U2) * np.cos(2 * np.pi * U1)
Y = r * np.sqrt(U2) * np.sin(2 * np.pi * U1)
circle = plt.Circle((0, 0), 1, color='g', fill=False)
fig,ax = plt.subplots()
ax.scatter(x = X, y = Y, s = 0.3)
ax.add_artist(circle)
plt.show()
- 株式会社セイシン-ブログ ヤコビアン
- Random Sampling
- self study - Generating random points uniformly on a disk - Cross Validated
- Generate Random Points over the Disk
- Disk Point Picking – from Wolfram MathWorld