As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label science. Show all posts

Interesting post, NASA discovers portals.

https://i.ytimg.com/vi/y3_vW5yrNek/maxresdefault.jpg

In the end of the post, it says:

However, there’s no doubt that this is a pretty cool announcement. Just not one that we can use to get to Tatooine or the Delta Quadrant.

Recently, I re-watched The Omega Directive episode of Star Trek: Voyager again. I probably have watched the series at least three or four times. I can tell you this, no one wants a portal to Delta Quadrant, because Borg is there! And more formidable enemy, Species 8472 by Borg’s designation, even Borg fears them. I think we need Captain Janeway, the old one.

Sigh, why is there no more Star Trek series? Don’t understand why people lose interest of space sci-fi, but not those nothing-is-real-but-scripted-reality-shows. If you want reality, go out; need some drama? look around, plenty.

I was window shopping at Community Contribution of Arch Linux Fourms for totally free new application, tried to see if I can find new toy. I saw this HC, after I read and saw some examples the author posted, I decided to give it a try.

1   Happy Valentine’s Day!

Too early? or too late?

r(t)=2-2sin(t)+sin(t)*sqrt(abs(cos(t)))/(sin(t)+1.4)
graphpeq(r(t)*cos(t),r(t)*sin(t),0,2pi,-3,3,-4,1)

2   No recursion? You can’t stop me!

If you try to define a recursion function, you will get:

fib(n)=if(n>=0,
  if(n==0,0,
    if(n==1,1,
      fib(n-1)+fib(n-2)
      )
    )
  )
Error : recursive definition.

Let’s trick HC!

fibr(n)=fib(n)
fib(n)=if(n>=0,
  if(n==0,0,
    if(n==1,1,
      fibr(n-1)+fibr(n-2)
      )
    )
  )

Some outputs:

> fib(10)==fibo(10)
1
> fib(70)
Error : too much recursion/nestedness. If you know what you are doing, you can bypass this with:
 \bpn.
Argument Error : if() : at least two arguments are needed (condition, true_branch, false_branch)
> \bpn
By pass is now on.
> fib(70)

You will have to wait until only God knows how long it takes…

Note

Now, HC is allowed to define recursion function:

fib(n) = if(n<2,n,fib(n-1)+fib(n-2))

, read more. (2010-08-24)

3   FFT! The FFT!?

Yes, the Fast Fourier transform!

fft(x)=for(k=0,k&lt;length(x),k+=1,
  xk=0;
  for(j=0,j&lt;length(x),j+=1,
    a=x[j];
    b=exp(-2pi*k*j*0i1/length(x));
    xk+=a*b;
    );
  print(xk);
  )

Example:

> x = [1,0,3i-3,4i5,5]
> fft(x)
13i2
-7.8203160070896799i3.7250338450183462
6.7264861191111235i2.6059037339171068
-8.4904181416113337i-1.3698357564173172
1.5842480295898901i-6.9611018225181358

Confirmed by result from SciPy:

>>> import scipy
>>> scipy.fft([1,0,3-3j,4+5j,5])
array([ 13.00000000+2.j        ,  -7.82031601+3.72503385j,
         6.72648612+2.60590373j,  -8.49041814-1.36983576j,
         1.58424803-6.96110182j])</pre>

Note: the representations of complex number are different.

Note

Here is a shorter version:

fft(x)=for(k=0,k&lt;length(x),k+=1,
  for(j=0,j&lt;length(x),j+=1,
    a=x[j];
    b=exp(-2pi*k*j*0i1/length(x));
    xk=if(j==0,a*b,xk+a*b);
    );
  y=if(k==0,[xk],join(y,[xk]));
  )

(2010-08-24)

The result can be retrieved by y.

4   Conclusion

This is a great CLI program, I am going to replace SpeedCrunch. You can do some simple programming, though I found it’s still limited. (What do you expect? Signal processing using a calculator?) When I installed SpeedCrunch because I wanted one can allow me to easy input, bc is not so friendly, even I prefer CLI over GUI. Now, HC can do things I need and it’s a CLI and it’s resource-friendly. Definitely the top choice for me!

It has vector but it’s not much you can do with it at this moment, but if you just use it for 1+1, it can do much more than that. If you don’t like CLI, don’t worry, it provides GUI as well. But I didn’t try it, so no comments on that.