AutoHotkey Community

It is currently May 26th, 2012, 6:47 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 71 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: March 11th, 2008, 11:45 pm 
Offline

Joined: February 10th, 2007, 5:18 am
Posts: 92
It seems it would be wise to round off numbers eventually, for example, sin(pi) and cos(pi/2) without a doubt is equal to 0 but the calculator gives a -16th power.

I understand that number is near 0 and can be accepted as 0, but these expressions in which the answer has a finite answer, the answer should be shown accurately.

Also, give the option of using degree mode with trig functions, and having a command switch between radian and degree.

Another suggestion, is to do a limits as x approaches a number. My suggestion just add a really small number to the x value and find the value of the function.

Also, having calculus functions would be a great tool.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2008, 12:23 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
maximo3491 wrote:
it would be wise to round off numbers eventually, for example, sin(pi) and cos(pi/2) without a doubt is equal to 0 but the calculator gives a -16th power.
I see no easy way to do it. If the argument is not an exact number, any rounding causes more harm. Pi is not symbolic, so it is never exact in the calculator. If you are interested in fix point output, you can always write it out explicitly:
Code:
round(sin(pi),9)

maximo3491 wrote:
give the option of using degree mode with trig functions, and having a command switch between radian and degree.
It is a good idea, although for my purposes the built in constants (rad and deg) were enough.
Code:
sin(45*rad)
atan(1)*deg
For casual users, not familiar with the standard trigonometric functions, a DEG/RAD button can be easier.
maximo3491 wrote:
do a limits as x approaches a number. My suggestion just add a really small number to the x value and find the value of the function.
It is also a good idea, but not so easy to implement. If you want the limit of x/sin(x) when x approaches to 0, what is a really small number? 0.001? 1.0e-99? 1.0e-299? Also, sometimes built in functions are relatively inaccurate next to a singularity, so a “really small” number can give a wrong result.
maximo3491 wrote:
having calculus functions would be a great tool.
In version 3.5 there are three implemented: the error function, the (upper) incomplete gamma function and log-gamma. I hope dynamic expressions will be soon added to AHK, and I would not need lexiKos’ low level functions any more. I have been waiting for these with posting version 3.5. What functions would you like implemented?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2008, 2:09 am 
Offline

Joined: February 10th, 2007, 5:18 am
Posts: 92
well sin(0), sin(pi), cos(pi/2), and cos(3pi/2) are exactly equal to 0. If you are familiar with the unit circle, it provides proof of that.

For the limit, the small number i mentioned was very ambiguous. Sorry for that. What I meant to say was add a number like 10^-20 to the x value you wish to find the limit at because most likely, you will want to find the limit of a function at an undefined point.

Example:
Limit of f(x) = x^2/x as x approaches 0. That would be a divide by zero error, but if you were to add 10^-20 to x, the result would be very close to the actual limit.

I assume you know calculus, so for this, the limit from the left and right must be checked because some equations (like (x^2)/(x-1) for example) have the limit from either side as different. However if the limits from both sides were to be equal, that value is also the normal limit.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2008, 3:32 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
maximo3491 wrote:
well sin(0), sin(pi), cos(pi/2), and cos(3pi/2) are exactly equal to 0.
You did not get it: pi is a variable, containing an approximate number. You can even change its value to 4 (if you live in Indiana), or anything else you like. There is no easy way to figure out if you mean sin(π) by sin(3.1415926535897931) or the argument is meant (as it is) to be slightly less than π. Even if the script would search for the variable name “pi” and handled it symbolically, we still would face difficulties with sin(2*pi), sin(pi/2), x:=1;sin(x*pi), etc. For that a symbolic math engine was necessary, which is much harder than the current numeric evaluation.
maximo3491 wrote:
add a number like 10^-20 to the x value you wish to find the limit
This is, of course, not sufficient. If you want the limit of sin(x)/(x-π) when x approaches to π, you could start with x=pi (where the expression is not defined). Adding 10^-20 to x causes underflow, so it does not change the value of x, you get no limit this way. You need to add 10^-16, instead, but it is not a universal constant. Even if you make relative changes (multiply with 1+1.e-16), it fails at x=0. There is no universal additive constant around 0. Think about x/sin(1.e16*x).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2008, 5:25 am 
Offline

Joined: February 10th, 2007, 5:18 am
Posts: 92
The 1e-20 was an example I used. I do not know the limitations of coding, you are the expert at that.

For limits when referring to calculus however, adding the most minute decimal possible to a value that would originally make the function become undefined would make the function work. That is how calculators (and some mediocre computers) with a limit feature but no understanding of calculus actually calculate the limit. They add an infinitesimally small number to alter the x value enough so the result is real and still close enough to the answer that you are able to simply round off and achieve the actual limit.

I'm simply explaining how the limit is calculated by programs with no understanding of any form of calculus. Whether you can achieve this or not, I have no idea. I am just giving a suggestion of a function to add to the cornucopia of others you have already implemented.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Version 3.5
PostPosted: March 13th, 2008, 6:02 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Version 3.5 is available for testing. More than a thousand lines are changed/added since the last release, so there could be some bugs. You can download the exe, source, ini, and a sample history file, with many examples.

Here is the header of the script, which list the changes:
Quote:
Popup AHK calculator v.3.5
Works with AHK 1.0.47.04 ... 1.0.47.06
Includes lexiKos' lowlevel functions (http://www.autohotkey.com/forum/viewtopic.php?t=26300)

Measure width of all text/header for consitent display in any font, fontsize and dpi settings
dllcall("GetDialogBaseUnits","UInt") --> pixels for tabstop (dpi dependent)
New user interface: Expression imput (~Paper) on top, results below.
-- Enter evaluates current line.
---- In last line: insert blank line below.
-- Ctrl-Enter: insert newline char
-- Shift-Enter: execute (multiline, partial line) selection
Ctrl-= duplicate current line
ESC clear current line
Ctrl-Z undo/redo last edit

Context menu in calculator window (right click, Appskey):
--- Help,Load,Save,Hide,Exit
--- duplicate_line,clear_line,select_line,select_all,undo
--- cut,copy,paste,delete
Removed Alt-A/U/E history editing (history is now directly editable)
New context menu and tray menu items, shortcuts:
-- Alt-E: appEnd-to-history
-- Alt-S: Save selection
-- Alt-W: Write history to file.

Tab: insert line-end from first/next match (restarts after edit of expr)
--- completed part is selected (blue)
--- Ctrl-Z: previous/this match
Shift-Tab: insert line-end from last/previous match

Incremental search in expressions:
-- Alt-F toggles search field, ESC closes
-- Tab/Shift-Tab: next/previous match
-- Enter: 1st match
-- UP arrow: goto found text

Incremental search in Help (Enter/Tab/Shift-Tab: 1st/next/prev match)
-- Up/Down: scroll help text

New keys in calc.ini:
-- MaxHist=99 number of input lines read from history (more saved)
-- KeptOutput=9 number of last results kept in output history _1, _2...

New construct: ";;" line-end comment
Multi-line results shown in one line, `n --> ¦, long lines are truncated (use msg() instead)
Changed msg(x[,x1...,x9]): up to 10 arguments in separate lines
Added run(file): execute list of expressions stroed in file
Added time(Format="",Time=""): formatted time (now) ~ AHK's FormatTime
Added Mode(["DEGree/RADians"]): set/toggle trigonometric domain
Changed all trigonometric functions to work in selected domain
Added FFormat(["format"]): set floating point format, default 0.16e
Window title now shows trig mode [RAD] and floating pt format [0.16e]
Added constants
--- Dmax = 1.7976931348623157e+308 (largest double)
--- Dmin = 2.2250738585072014e-308 (least positive normalized double)
--- Deps = 1.1102230246251565e-016 (=smallest douple: 1 + Deps > 1)

Added fnext(x[,d=1]): next float (add ±d to LS bits of x) for left/right limit
Added f2int(d): integer representation of bits of floating point (double) d
Added int2f(i): floating point representation (double) of bits of integer i

Added Bin2Hex(Addr,Len): Convert Len bytes @ Addr to hex stream
Added Hex2Bin(ByRef Bin, Hex): Convert Hex stream to binary, store in var Bin
Added BC(NumStr,InputBase,OutputBase): Base Conversion
Added from0(x): round away FROM 0
Added to0(x): round toward TO 0 (truncate)

Added diff(y,x): (~differential) y[i] <- x[i+1]-x[i], i=1..x[0]-1
Added cumsum(y,x): (~integral) y[i] <- x[i]+x[i-1]+..+x[1], i=1..x[0]

Added Error function erf(x), related to the normal distribution
Added GAMMA(a[,x]): upper incomplete gamma: Integral(t**(a-1)*e**-t, t=x..inf)
Added LnGamma(a): direct method (less overflow) [balanced: speed vs. code complexity]

Start and End limits of the Axes are now shown in graphs

A few new features were based on maximo3491’s suggestions:
- All trigonometric functions work now in either Degrees or Radians. The domain can be changed with the Mode() function. The current selection is shown in the title bar of the window.
- Similarly, the computation precision can be set with the Fformat() function, and it is shown in the title bar. The default is the maximum in scientific notation: 0.16e. The parameter is directly given to SetFormat Float, ...
- fnext(x,d) gives the next (normalized) floating point number (double) at a distance of d from x, in the least significant bits. If d=1 the result is the smallest possible machine number larger than x. If an expression is undefined, like “x:=0;sin(x)/x”, you can calculate its (right) limit, if it exists, with “x:=fnext(0);sin(x)/x” or its left limit with “x:=fnext(0,-1);sin(x)/x”. Some built in functions might not be very accurate close to a singularity, so another try with fnext(…,100) could give a sanity check.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2008, 7:13 pm 
Can I plot points?
Would be nice if you can plot a large array of points or vectors.

A possible use would be to import a list of points, do aninterpolation an plot the resulting graph along with the points.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2008, 8:32 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
There are a few different issues here.

1. You can import data, e.g. with copy and paste in the “more” or “assign” function, at most 30 entries at a time.
Code:
more(`x,9,4,1,0,1,4,9,16,25)

2. You can plot the points stored in any vector
Code:
plot(x)

3. However, there is no explicit interpolation function (yet), so the graph will consist of straight lines.
4. There is no convenient way to export the points of a plot. I think it is not needed, if the vector creating the points of the plot can be easily exported.

To facilitate this kind of jobs, I will look into adding:
a. A simple way to read data from a file to a vector
b. Explicit interpolation (up-sampling)
c. A simple way to write a vector to a file


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2008, 5:33 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I updated 3.5 beta:

Added:
Solve3(x,a,d,c,b): solve the tridiagonal system [a,d,c]*x = b for x
UpSample('z',y,p): insert p points in (y[i],y[i+1]) via natural cubic spline

CBget('x') : Get vector from the ClipBoard (CSV format: 1, "ab", cd)
CBput(x[,form]): Put formatted vector to the ClipBoard [comma separated]

Solve3 is needed internally for the optimal spline interpolation in UpSample, but you can use it for general purposes:
Code:
Solve Tridiagonal linear system: a[1..n-1], d[1..n], c[1..n-1], b[1..n] --> x[1..n]
d[1]x[1] + c[1]x[2]                                                              = b[1]
a[1]x[1] + d[2]x[2] + c[2]x[3]                                                   = b[2]
           a[2]x[2] + d[3]x[3] + c[3]x[4]                                        = b[3]
                                    . . . .                                      = . . .
                                        a[n-2]x[n-2] + d[n-1]x[n-1] + c[n-1]x[n] = b[n-1]
                                                       a[n-1]x[n-1] +  d[n] x[n] = b[n]

Solving general n×n linear systems of equations requires n**2 variables and n**3 operations, which can be too big and too slow in AHK. Tridiagonal systems use only 7n variables and the number of operations is also proportional to n.

The function UpSample takes a sequence y, and inserts p interpolated points in between its entries. The method used is the “natural cubic spline”, which corresponds the total minimal tension of a flexible rod fitted to the base points (i,y[i]). Try the following plots to see the nice smoothing effects (closing the graph window between plots):
Code:
plot(assign(`y,1,2,4,8,16)) ;; coarse exponential curve
plot(upsample(`yy,assign(`y,1,2,4,8,16),19)) ;; smoothed exponential curve
plot(assign(`y,1,0,1,0,1)) ;; saw-tooth
plot(upsample(`yy,assign(`y,1,0,1,0,1),19)) ;; smooth graph (look @ endpoints!)


If you want to externally use a vector computed in the calculator, CBput helps:
Code:
CBput(upsample(`yy,assign(`y,1,0,1,0,1),4),'%.6g | ') ;; Copy formatted interpolated data
(Be careful, the version of lexiKos’ low level functions used in the calculator don’t handle strings very well. E.g. strings cannot contain commas, quotes or back-quotes.) The result will be in the Windows clipboard, ready to be pasted, wherever you want.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 7:05 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Laszlo wrote:
(Be careful, the version of lexiKos’ low level functions used in the calculator don’t handle strings very well. E.g. strings cannot contain commas, quotes or back-quotes.)
I've fixed the issue with commas. Could you elaborate on "quotes or back-quotes"? Quotes must be doubled to be interpreted literally (unless they are enclosed in 'single quotes'), just as in normal expressions. Back-quotes should not be an issue.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 4:10 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Your fix for commas works. Thanks! I update the calculator with it, and upload. Back quotes (`n, `t) also work, but they interfere with the calculator's word quoting feature. I have to look into it.

Mixing single and double quotes can sometimes be unintuitive, but it is not a problem in the LowLevel functions. (Sorry, my mistake. Quotes don't act like parentheses.) E.g. 't"d' puts a double quote in the middle. If we include this into a double quoted string: "b't"d'c", we have a syntax error.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2008, 1:24 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I replaced the 3.50 beta with 3.51, at the same location (exe, source, ini, history). The changes:

- Updated the included LowLevel functions with Lexikos' update, to handle quoted commas
- Bugfix in parsing ";" separated commands (ignore quoted ";"s)
- ";;" in literal strings is not treated as line-end comment
- Improved `var -> "var" replacement (not in quotes, to keep `n,`t...)
- `n, `t, ... are now supported in strings (mainly used in the format string of CBput)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 11:37 am 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
autohotkey dowsnt respond when i run it
'send error report' occurs

???


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2010, 6:16 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
It only works with AHK version 1.0.47.04 ... 1.0.47.06, because it uses Lexicos' low level functions, and they have not been updated since. You can still run the compiled exe.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 3rd, 2010, 11:11 am 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
brilliant
brilliant
brilliant
brilliant
brilliant


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 71 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], mrhobbeys, nothing, siterip, Stigg and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group