Dyalog APL (no builtin), (削除) 13 (削除ここまで) 12 bytes
Dyalog does have the builtin ⍟, but this way it's more fun :)
(⊢-1-÷∘*)⍣=⍨
Basically just Newton's method:
$$ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} $$
where (L is the number we are taking the log of)
$$ f(x) = e^x - L \\ f'(x) = e^x \\ x_{n+1} = x_n - \frac{e^{x_n} - L}{e^{x_n}} = x_n - 1 - \frac L {e^{x_n}} $$
(⊢-1-÷∘*)⍣=⍨
⍨ ⍝ x_0 is L
⍣= ⍝ repeat Newton's method until x_n and x_n+1 are "equal":
⊢-1- ⍝ x_n - 1 -
÷∘* ⍝ L / e^x_n
💎 Created with the help of Luminespire at https://vyxal.github.io/Luminespire
"Equal" here means
$$ \left|x_n-x_{n+1}\right|\leq10^{-14}\max\left(\left|x_n\right|, \left|x_{n+1}\right|\right) $$
gotta say, ln(1) resulting in 1e-16 is kinda annoying but well within the spec
This is 1 byte less than an implementation of Jos Woolley's, 1e×ばつ ̄1+*∘1e ̄9, but probably still has some room to be golfed further.
- 1.3k
- 6
- 20