logarithm

java.lang.Math.log replaced by intrinsic call, why not java.lang.Math.exp()?

时光毁灭记忆、已成空白 提交于 2019-11-28 10:04:31
问题 I'm reasking a question that had too little attention I think: Why does this simple code (simply a call to Math.log() ): Double thisdouble = Math.log(10); With a breakpoint on line 275 of Math.class of the jdk1.7.0_11: 274 public static double log(double a) { 275 return StrictMath.log(a); // default impl. delegates to StrictMath 276 } Not stop execution in debug mode? Can somebody try this on his/her own machine (I'm using Eclipse)? Calling Math.exp() and debugging the Math.exp (line 254)

Is Swift dictionary of indexed for performance? Even for exotic types (UUID)?

a 夏天 提交于 2019-11-28 09:30:29
问题 I want to construct some arrays that will remain in order to get fast searches. If I use something like this: let dictionary: [Int:Int] = [:] for i in 0 ..< 10000000 { dictionary[i] = 0 } Would the query: dictionary[n] == nil be performed in logarithmic time? If yes, is it the same for other types: Float, Double, String. And finally, I need it to work with the UUID type, will it work? 回答1: Swift's Dictionary is implemented with a hash table, therefore lookups will typically be done in O(1)

NumPy: Logarithm with base n

时间秒杀一切 提交于 2019-11-28 07:08:13
From the numpy documentation on logarithms , I have found functions to take the logarithm with base e , 2 , and 10 : import numpy as np np.log(np.e**3) #3.0 np.log2(2**3) #3.0 np.log10(10**3) #3.0 However, how do I take the logarithm with base n (e.g. 42) in numpy? Banana To get the logarithm with a custom base using math.log : import math number = 74088 # = 42**3 base = 42 exponent = math.log(number, base) # = 3 To get the logarithm with a custom base using numpy.log : import numpy as np array = np.array([74088, 3111696]) # = [42**3, 42**4] base = 42 exponent = np.log(array) / np.log(base) #

Log of a very large number

99封情书 提交于 2019-11-28 04:46:45
问题 I'm dealing with the BigInteger class with numbers in the order of 2 raised to the power 10,000,000. The BigInteger Log function is now the most expensive function in my algorithm and I am desperately looking for an alternative. Since I only need the integral part of the log, I came across this answer which seems brilliant in terms of speed but for some reason I am not getting accurate values. I do not care about the decimal part but I do need to get an accurate integral part whether the

ValueError: math domain error

醉酒当歌 提交于 2019-11-28 04:36:23
I was just testing an example from Numerical Methods in Engineering with Python . from numpy import zeros, array from math import sin, log from newtonRaphson2 import * def f(x): f = zeros(len(x)) f[0] = sin(x[0]) + x[1]**2 + log(x[2]) - 7.0 f[1] = 3.0*x[0] + 2.0**x[1] - x[2]**3 + 1.0 f[2] = x[0] + x[1] + x[2] -5.0 return f x = array([1.0, 1.0, 1.0]) print newtonRaphson2(f,x) When I run it, it shows the following error: File "example NR2method.py", line 8, in f f[0] = sin(x[0]) + x[1]**2 + log(x[2]) - 7.0 ValueError: math domain error I have narrowed it down to the log as when I remove log and

Highcharts - best way to handle and display zero (or negative) values in a line chart series with logarithmic Y axis

会有一股神秘感。 提交于 2019-11-28 04:02:52
问题 In my HighChart line graphs, the series data is being fed from my Ruby on Rails application dynamically. Sometimes the series values are zeros or less which is a problem for HighCharts and it throws the following exception: Highcharts Error #10 Can't plot zero or subzero values on a logarithmic axis So as a work-around, I process my ruby array to conditionally replace a zero of less value with an insignificant positive number, .e.g. 0.00001 as shown below: oil_vol_array = d_array[1].map { |e|

Log to the base 2 in python

旧城冷巷雨未停 提交于 2019-11-28 03:44:10
How should I compute log to the base two in python. Eg. I have this equation where I am using log base 2 import math e = -(t/T)* math.log((t/T)[, 2]) It's good to know that but also know that math.log takes an optional second argument which allows you to specify the base: In [22]: import math In [23]: math.log? Type: builtin_function_or_method Base Class: <type 'builtin_function_or_method'> String Form: <built-in function log> Namespace: Interactive Docstring: log(x[, base]) -> the logarithm of x to the given base. If the base not specified, returns the natural logarithm (base e) of x. In [25]

What is O(log* N)?

浪子不回头ぞ 提交于 2019-11-28 03:18:24
What is O(log* N) ? I know big-Oh, the log* is unknown. O( log* N ) is " iterated logarithm ": In computer science, the iterated logarithm of n, written log* n (usually read "log star"), is the number of times the logarithm function must be iteratively applied before the result is less than or equal to 1. The log* N bit is an iterated algorithm which grows very slowly, much slower than just log N . You basically just keep iteratively 'logging' the answer until it gets below one (E.g: log(log(log(...log(N))) ), and the number of times you had to log() is the answer. Anyway, this is a five-year

What kind of logarithm functions / methods are available in objective-c / cocoa-touch?

≡放荡痞女 提交于 2019-11-28 01:52:53
I've tried searching for logarithm + objective-c, but all I get is math test pages from teachers, or explanations what a logarithm is ;) I've got some measurements that are like 83912.41234 and others are 32.94232. I need to press down this huge spectrum into something between 0 and 100, and that 32.94232 would habe to be at least something bigger than 2, where the 83912.41234 would be something near 100. So I think a logarithm function will be my friend here. UPDATE: I've came across the math.h file through "Open Quickly" (very nice command in Xcode: SHIFT + CMD + D), and there, big surprise:

Big O notation Log Base 2 or Log Base 10 [duplicate]

强颜欢笑 提交于 2019-11-27 19:20:09
This question already has an answer here: Is Big O(logn) log base e? 7 answers When articles/question state that the Big O running time of the algorithm is O(LogN) . For example Quicksort has a Big O running time of O (LogN) where the it is Log base 10 but Height of binary tree is O(LogN+1) where it is Log base 2 Question 1)I am confused over whether is it Log base 10 or Log base 2 as different articles use different bases for their Logarithm . 2) Does it make a difference if its Log base 2 or Log base 10?? 3)Can we assume it mean Log base 10 when we see O(LogN)??? I think it does not matter