logarithm

What does “log*” mean?

僤鯓⒐⒋嵵緔 提交于 2019-12-09 07:41:27
问题 I have come across the term O(log* N) in a book I'm reading on data structures. What does log* mean? I cannot find it on Google, and WolframAlpha doesn't understand it either. 回答1: It's iterated logarithm. See here for a description of lots of different time complexities, and here for more details on the iterated logarithm itself. The iterated logarithm is the number of times the logarithm has to be applied before the result becomes one or less. 回答2: It's called iterated logarithm function.

How do you do natural logs (e.g. “ln()”) with numpy in Python?

霸气de小男生 提交于 2019-12-09 04:27:44
问题 Using numpy, how can I do the following: ln(x) Is it equivalent to: np.log(x) I apologise for such a seemingly trivial question, but my understanding of the difference between log and ln is that ln is logspace e? 回答1: np.log is ln , whereas np.log10 is your standard base 10 log. Relevant documentation: http://docs.scipy.org/doc/numpy/reference/generated/numpy.log.html http://docs.scipy.org/doc/numpy/reference/generated/numpy.log10.html 回答2: Correct, np.log(x) is the Natural Log (base e log)

Haskell logbase error

爷,独闯天下 提交于 2019-12-08 19:26:53
问题 I am trying to calculate the length of an Integer in Haskell, using the fact that the length is equal to truncate (log10(x)+1) . Using Integers I created: len :: Integer -> Integer len i = toInteger (truncate (logBase 10 (fromIntegral i)) + 1) Unfortunately, not all numbers get the correct length. I tried a few different cases and found that: logBase 10 10 = 1.0 logBase 10 100 = 2.0 logBase 10 1000 = 2.9999..6 logBase 10 10000 = 4.0 logBase 10 100000 = 5.0 logBase 10 1000000 = 5.9999999 Is

Plot size = 1/{N∗⌈log2N⌉∗[(1/70)/60]} in R?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 12:52:51
问题 size = 1/{N∗⌈log_2(N)⌉∗[(1/70)/60]} How can I plot this function with R? (⌈⌉= ceil) For example: With label "size" for y-axis and "N" for x-axis. N >= 2, N is natural Number (2,3,4,5,6,...) 回答1: Let's define the function f <- function(N) 1 / (N * ceiling(log2(N)) * 1/70/60) Plot with base R in the range [1,20] curve(f, from = 1, to = 20, n = 10^3, type = "p", cex = 0.1) Plot with ggplot2 in the range [1,20] library(ggplot2) ggplot(data.frame(N = c(1, 20)), aes(N)) + stat_function(fun = f,

Log2 approximation in fixed-point

岁酱吖の 提交于 2019-12-08 07:51:05
问题 I'v already implemented fixed-point log2 function using lookup table and low-order polynomial approximation but not quite happy with accuracy across the entire 32-bit fixed-point range [-1,+1). The input format is s0.31 and the output format is s15.16. I'm posting this question here so that another user can post his answer (some comments were exchanged in another thread but they prefer to provide comprehensive answer in a separate thread). Any other answers are welcome, I would much

Design of an algorithm problems of Clog n[C++ code]

不打扰是莪最后的温柔 提交于 2019-12-08 05:33:47
问题 Two sorted arrays of integers A[1..N] and B[1..N] are provided in ascending order . Q:Design an O(log N)-time algorithm for finding out the median of all 2N integers. N may not power of 2 . To make thing easy, we can assume O(1) algorithm which return m such that: 2^m < N < 2^m+1 My problems: N may not be power of 2 , what does that mean? (understood) I don't know how to change the input and make the length to power of 2 after found min and max elements from both array A and B . 回答1: You can

How to get a logarithmic distribution from an interval

百般思念 提交于 2019-12-07 18:57:56
问题 I am currently trying to cut an interval into not equal-width slices. In fact I want the width of each slice to follow a logarithmic rule. For instance the first interval is supposed to be bigger than the second one, etc. I have a hard time remembering my mathematics lectures. So assuming I know a and b which are respectively the lower and upper boundaries of my interval I , and n is the number of slices: how can I find the lower and upper boundaries of each slice (following a logarithmic

How to implement natural logarithm with continued fraction in C?

你。 提交于 2019-12-07 13:53:24
问题 Here I have a little problem. Create something from this formula: This is what I have, but it doesn't work. Franky, I really don't understand how it should work.. I tried to code it with some bad instructions. N is number of iteration and parts of fraction. I think it leads somehow to recursion but don't know how. Thanks for any help. double contFragLog(double z, int n) { double cf = 2 * z; double a, b; for(int i = n; i >= 1; i--) { a = sq(i - 2) * sq(z); b = i + i - 2; cf = a / (b - cf); }

Problem with arithmetic using logarithms to avoid numerical underflow (take 2)

别等时光非礼了梦想. 提交于 2019-12-07 02:54:49
问题 I have two lists of fractions; say A = [ 1/212, 5/212, 3/212, ... ] and B = [ 4/143, 7/143, 2/143, ... ] . If we define A' = a[0] * a[1] * a[2] * ... and B' = b[0] * b[1] * b[2] * ... I want to calculate a normalised value of A' and B' ie specifically the values of A' / (A'+B') and B' / (A'+B') My trouble is A are B are both quite long and each value is small so calculating the product causes numerical underflow very quickly... I understand turning the product into a sum through logarithms

Python math module

删除回忆录丶 提交于 2019-12-06 18:33:30
问题 Whenever I try to use any of the built-in functions of Python's exponentiation and logarithms module, I get an error like this: NameError: name 'sqrt' is not defined I have tried using math.sqrt(4) , sqrt(4) and sqrt(4.0) , but none of them work. The exception is pow , which works as it's supposed to. This is really strange and I'm not sure what's wrong. 回答1: pow is built into the language(not part of the math library). The problem is that you haven't imported math. Try this: import math math