You are not logged in.

#51 2010-09-02 01:38:17

livibetter
Member
From: Taipei
Registered: 2008-05-14
Posts: 95
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

y27 wrote:

@zeros:
Added, with the same functionality as your code smile

Also added ones(), which does the same as zeros() but puts 1's in the array. This can be useful since it's then possible to generate an array containing any constant numbers (ie to generate a list of 3 42's, one can do ones(3) * 42).

Great job! smile

TIme to update the fft()!

Previous ~344ms:

fft(x)=for(k=0;N=length(x);y=[],k<N,k+=1,
  for(j=0;dd=-2pi*k*0i1/N;xk=0,j<N,j+=1,
    xk+=x[j] * exp(dd*j);
    );
  y=join(y,[xk]);
  if(k==N-1,y);
  )
print(fft([1,0,3i-3,4i5,51,0,3i-3,4i5,5,0,3i-3,4i5,51,0,3i-3,4i5,5]))

Fully use v[index] ~375ms:

fft(x)=for(k=0;N=length(x);y=zeros(N),k<N,k+=1,
  for(j=0;dd=-2pi*k*0i1/N,j<N,j+=1,
    y[k]+=x[j] * exp(dd*j);
    );
  if(k==N-1,y);
  )
print(fft([1,0,3i-3,4i5,51,0,3i-3,4i5,5,0,3i-3,4i5,51,0,3i-3,4i5,5]))

For better performance ~344ms (same as first one):

fft(x)=for(k=0;N=length(x);y=zeros(N),k<N,k+=1,
  for(j=0;dd=-2pi*k*0i1/N;xk=0,j<N,j+=1,
    xk+=x[j] * exp(dd*j);
    );
  y[k]=xk;
  if(k==N-1,y);
  )
print(fft([1,0,3i-3,4i5,51,0,3i-3,4i5,5,0,3i-3,4i5,51,0,3i-3,4i5,5]))

Offline

#52 2010-09-03 00:43:00

y27
Member
Registered: 2009-05-27
Posts: 147
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

Nice smile

The slower performance of the second version you posted is probably due to how hc evaluates

y[k]+=x[j] * exp(dd*j);

It first evaluates

y[k] + (x[j] * exp(dd*j))

for which it has to get the value of y[k], which takes longer than taking just a value of a simple variable like xk in the third version.

Then it does:

y[k] = result of previous code

for which it has to do some work again to find the kth element of y.


By the way, I've released HC v3.1, which pretty much includes the various changes and fixes livibetter suggested (thanks smile ) and a few other things.
Changelog:

  - added more detailed syntax error messages
  - fixes and enhancements to vectors; for example, it is now possible to use assignment by index (ie. v[2] = 3)
  - on *NIX, it is now possible to use ~ in filenames and it will get properly expanded
  - added zeros() and ones()
  - bugfixes

Offline

#53 2010-09-03 01:26:42

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

Thanks a ton for this! It seems most calculator creators ignore people who run all of their programs in a terminal, typically those with tiling WM's. smile

Last edited by cesura (2010-09-03 01:26:58)

Offline

#54 2010-09-03 10:55:37

livibetter
Member
From: Taipei
Registered: 2008-05-14
Posts: 95
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

Thanks for explanation, y27!

I wonder if anyone has tried:

ones(1000)

I got a segmentation fault, then I saw a working buffer `tmp` is capped to size `MAX_EXPR`, which is 16384 bytes. Around 400-500 is enough to cause segmentation fault.

I don't expect seeing it getting fixed or graceful warning message, but seeing a new design of HC, because `ones(10000)` took 2+ seconds and `ones(20000)` took 8+ seconds. It's not the generation of vector string takes that long but some others after the vector string being generated, I guess.

I think I just like pushing... ;p

Last edited by livibetter (2010-09-03 10:56:24)

Offline

#55 2010-09-03 13:41:27

y27
Member
Registered: 2009-05-27
Posts: 147
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

itsbrad212 wrote:

Thanks a ton for this! It seems most calculator creators ignore people who run all of their programs in a terminal, typically those with tiling WM's. smile

I'm glad you find it useful smile



livibetter wrote:

Thanks for explanation, y27!

I wonder if anyone has tried:

ones(1000)

I got a segmentation fault, then I saw a working buffer `tmp` is capped to size `MAX_EXPR`, which is 16384 bytes. Around 400-500 is enough to cause segmentation fault.

I don't expect seeing it getting fixed or graceful warning message, but seeing a new design of HC, because `ones(10000)` took 2+ seconds and `ones(20000)` took 8+ seconds. It's not the generation of vector string takes that long but some others after the vector string being generated, I guess.

I think I just like pushing... ;p

Hmm, this was due to hc simplifying the resulting list which is not necessary for zeros() or ones(). Made an optimization that checks whether the resulting list needs simplifying; and if not, it doesn't do anything with it, so zeros() and ones() should now be much faster. Also, the limit is now higher (I tried doing zeros(5000) and it still works), because what happens when a list like [1,1,1] is simplified is that hc_result_() (note the underscore) is called, which does not do any final formatting "niceification" (for speed), so [1,1,1] becomes something like [1.00000,1.00000,1.00000] which takes more space than just [1,1,1].

In the latest commit, I also added a mechanism to check whether the list is too big, so it doesn't segfault now even for very big input (it should just print Error : Overflow).

Btw, if you really feel you need to generate even larger arrays, you can always increase MAX_EXPR in hc.h and recompile.

Offline

#56 2010-10-31 23:19:03

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

How may I use rlwrap with hc, to save my command history across sessions? Running hc with 'rlwrap hc' unfortunately doesn't enable it (rlwrap does work with Mathematica's cli client).


Registed Linux User 483618

Offline

#57 2010-11-02 00:36:56

y27
Member
Registered: 2009-05-27
Posts: 147
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

Sorry but I have no experience with rlwrap; from a quick google it seems to wrap an existing program's user input in readline? Maybe it's an issue that HC CLI already uses readline and therefore it can't properly wrap it since it's already using it?

Anyway, I'll check it out in more detail later this week if I have some time.

Offline

#58 2010-11-10 03:06:14

y27
Member
Registered: 2009-05-27
Posts: 147
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

Sorry for the delay, I found the problem though; the rlwrap manpage says that for commands that already use readline, you need to add -a. So, to make rlwrap work with hc, use:

rlwrap -a hc

Also, I just posted the new version, 4.0, in AUR, the changes in this version are pretty much some minor adjustments to graphs and addition of graphvalues() to draw a table of values; in statistics, I added linreg() to do a linear regression of data; and finally, I added some functional programming concepts, for now there are lambda functions and map() (check http://houbysoft.com/hc/fnp.php for usage).

As always, feedback and thoughts are welcome!

Last edited by y27 (2010-11-10 03:07:12)

Offline

#59 2010-11-12 19:58:13

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: HC - A scientific, graphing, supp complex nums CLI and GUI calculator

y27 wrote:

Sorry for the delay, I found the problem though; the rlwrap manpage says that for commands that already use readline, you need to add -a. So, to make rlwrap work with hc, use:

rlwrap -a hc

Thanks a lot! Now this will not only help me with hc, but other math programs I used for which I had the same problem. Many thanks smile. Also thanks for the update to hc.

[Edit] But tabbing twice to obtain the list of functions does not work with rlwrap. Any other helpful suggestions are welcome smile. [/Edit]

Last edited by Sara (2010-11-13 04:39:01)


Registed Linux User 483618

Offline

Board footer

Powered by FluxBB