Post Reply 
A new RPL firmware for the 50g
12-31-2013, 04:49 AM
Post: #2
RE: A new RPL firmware for the 50g
(12-31-2013 03:04 AM)Claudio L. Wrote:  It wouldn't need to be in any particular language, I'd say as long as we get some pseudocode that can be understood by me (or other people helping me), it can be translated to C.
Compare translating this comment:
Code:

* Q := y^2/(sqrt((|x|+1)^2 + y^2) + (|x|+1))
* R := sqrt((|x|-1)^2 + y^2) +||x|-1|
* S := y^2/R if R<>0, 0 otherwise
* M := Q+R if |x|>=1, Q+S otherwise
* P := Q+S if |x|>=1, Q+R otherwise
* B := 2*x/(M+2)
* C := sqrt((P/(M+2))*(2-(P/(M+2))))
* sg(y,x) := sgn(y) if y<>0, -sgn(x) otherwise
* IM := sg(y,x)*lnp1((M/2) + sqrt((M/2)*((M/2)+2))) (sign replacement)
*
*        { arccos(B)            |B| <= (1/sqrt(2))
* RE1 := { arcsin(C)            |B| > (1/sqrt(2)) and B >= 0
*        { pi - arcsin(C)       |B| > (1/sqrt(2)) and B < 0
*
* RE2 := { arcsin(B)            |B| <= (1/sqrt(2))
*        { sgn(B)*arccos(C)     |B| > (1/sqrt(2))   (sign replacement)
*
to Python:
Code:

def sg(y,x):
    return sgn(y) if y != 0 else -sgn(x)

def inverse(x, y):
    Q = y**2/(sqrt((abs(x)+1)**2 + y**2) + (abs(x)+1))
    R = sqrt((abs(x)-1)**2 + y**2) +abs(abs(x)-1)
    S = y**2/R if R != 0 else 0
    M = Q+R if abs(x) >= 1 else Q+S
    P = Q+S if abs(x) >= 1 else Q+R
    B = 2*x/(M+2)
    C = sqrt((P/(M+2))*(2-(P/(M+2))))    
    IM = sg(y,x)*log1p((M/2) + sqrt((M/2)*((M/2)+2))) # sign replacement
    RE1 = acos(B) if abs(B) <= 1/sqrt(2) else asin(C) if B >= 0 else pi - asin(C)
    RE2 = asin(B) if abs(B) <= 1/sqrt(2) else sgn(B)*acos(C) # sign replacement
    return IM, RE1, RE2
And now imagine doing the same with SystemRPL:
Code:

:: C%>%% 2DUP DUP %%*SWAP %%ABS DUP %%1+ DUPDUP %%* 4PICK %%+
   %%SQRT %%+ 3PICKSWAP %%/ OVER %%1 %%- %%ABS DUPDUP %%* 5PICK
   %%+ %%SQRT %%+ 4ROLLOVER DUP %%0<>
   ITE
   %%/
   :: 2DROP %%0 ;
   UNROTOVER %%+ UNROT %%+ ROT %%1 %%< ?SKIPSWAP DUP %%2 %%+ ROTOVER
   %%/ %%2 OVER %%- %%* %%SQRT 5PICK DUP %%+ ROT %%/ ROT %%2 %%/ DUP
   %%2 %%+ OVER %%* %%SQRT %%+ %%LNP1 5ROLL 5ROLL DUP %%0=
   ITE :: DROP %%0< ; :: SWAPDROP %%0>= ;
   ?SKIP %%CHS
   UNROTDUP
   %%ABS %%.7 %%<= case :: SWAPDROPDUP %%ACOSRAD SWAP %%ASINRAD ;
   SWAPDUP %%ASINRAD SWAP %%ACOSRAD %%ABS
   ROT %%0>= ?SEMI
   %%CHS %%PI ROT %%- SWAP
;
Without the comments in the source code I don't think I'd be able to figure out what this piece of code does.
Others might be fluent in SystemRPL but I'm not.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: A new RPL firmware for the 50g - Thomas Klemm - 12-31-2013 04:49 AM
RE: A new RPL firmware for the 50g - Han - 01-01-2014, 06:39 AM
RE: A new RPL firmware for the 50g - Han - 01-01-2014, 07:27 PM
RE: A new RPL firmware for the 50g - Han - 01-02-2014, 03:44 AM
RE: A new RPL firmware for the 50g - Han - 01-03-2014, 03:14 PM



User(s) browsing this thread: 1 Guest(s)