Post Reply 
Change name for →Qπ - please suggest!
11-16-2017, 09:18 PM
Post: #21
RE: Change name for →Qπ - please suggest!
(11-16-2017 09:13 PM)DrD Wrote:  FP_RAT()
Maybe FPRAT
Find all posts by this user
Quote this message in a reply
11-16-2017, 09:24 PM
Post: #22
RE: Change name for →Qπ - please suggest!
FP_RAT() in capital letters indicating a home function could be an acceptable choice, second best, when RATAPPROX is too long, I have the impression, that I very often select functions from the menus, so length doesn't matter, and when I write a program I prefer short names, so 3 letters can be hit by an arbitrary name given to some subroutine.
Arno
Find all posts by this user
Quote this message in a reply
11-16-2017, 11:18 PM (This post was last modified: 11-16-2017 11:19 PM by primer.)
Post: #23
RE: Change name for →Qπ - please suggest!
(11-16-2017 05:50 PM)salvomic Wrote:  • rational_form

(11-16-2017 06:45 PM)DrD Wrote:  Since it involves changing a floating point to rational number....

Sorry,
but sqrt(2) is not rational, but is irratonal no ?
So every name with "rational" only shoud be avoided.

maybe normalize(), but I don't like it too much myself Wink
or toALG() ?

primer
Find all posts by this user
Quote this message in a reply
11-17-2017, 12:02 AM
Post: #24
RE: Change name for →Qπ - please suggest!
(11-16-2017 11:18 PM)primer Wrote:  but sqrt(2) is not rational, but is irratonal no ?
→Qπ attempts to approximate expr into one of the following forms using digits of precision: p/q, (a/b)*√(p/q), (p/q)*π, ln(p/q) or e^(p/q)...
Rational under square root. This command is related to rational.
Find all posts by this user
Quote this message in a reply
11-17-2017, 12:06 AM (This post was last modified: 11-17-2017 08:08 AM by StephenG1CMZ.)
Post: #25
RE: Change name for →Qπ - please suggest!
What would a novice think QPI(4.5) means if they saw it in the source code and hadn't previously read this thread?
PPL supports implied multiplication, yes?
So QPI(4.5) can be parsed as QPI*(bracketed-expression), yes?
I haven't looked it up yet, but I might guess its a constant equal to QuarterPi, or Pi/4, multiplied by 4.5. (For comparison: many algorithms use the constant TwoPi = 2*Pi to avoid the cost of a multiply).

So let's forget the reference to Pi, at least, which it has nothing to do with.

To be consistent with other HP Prime conversion names, such as mat2list, something like fp2exact seems reasonable for now. However, the "fp" part bothers me.
Why?
What would you expect fp2exact(#2) to do?
Or fp2exact(2.1+2.2i)
The intuitive result of giving it a complex number seems obvious enough:
21/10 + (22/10)i or something (I haven't checked exactly what the output should be, but I guess it should be complex)
So do we need
Complex2exact
String2exact etc.?

Perhaps just
Convert2exact(anything), or ToEXACT for brevity,
But then for consistency mat2list ought to be
Convert2list or Tolist etc.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-17-2017, 12:09 AM
Post: #26
RE: Change name for →Qπ - please suggest!
(11-17-2017 12:02 AM)Voldemar Wrote:  Rational under square root. This command is related to rational.
Yes "related", but result isn't rational.
And I found weird to call that function something like to_rat() or fp_rat() which doesnt return a rational result.

primer
Find all posts by this user
Quote this message in a reply
11-17-2017, 12:22 AM (This post was last modified: 11-17-2017 12:25 AM by AlexFekken.)
Post: #27
RE: Change name for →Qπ - please suggest!
(11-16-2017 07:39 PM)DrD Wrote:  Since any number can be divided by 1, they are all rational numbers.

Am I missing something or is this is a suggestion to redefine "rational number" to mean "any number"?

Suggesting that square roots, multiples of pi etc should be called "rational numbers" in general seems pretty silly to me. And baking it into function name extremely misleading.

EDIT: oops this was picked up already...
Find all posts by this user
Quote this message in a reply
11-17-2017, 12:28 AM
Post: #28
RE: Change name for →Qπ - please suggest!
(11-17-2017 12:09 AM)primer Wrote:  And I found weird to call that function something like to_rat() or fp_rat() which doesnt return a rational result.
You are right. Let’s try to figure out another name.
Find all posts by this user
Quote this message in a reply
11-17-2017, 12:39 AM
Post: #29
RE: Change name for →Qπ - please suggest!
How about «show rational part»?
SRP Smile
Find all posts by this user
Quote this message in a reply
11-17-2017, 12:52 AM
Post: #30
RE: Change name for →Qπ - please suggest!
I don't know what is meaning of QPI output. Is it only visualition or it is something which can be stored into variable (or variables as there are p and q) for example?

If it is the former, then it is similar to [a b/c] key and it could be on almost empty menu bar (where is nothing more than Sto >) as f(p/q) or something.

I'm sorry if I'm talking nonsense.

Prime G2, 15C CE
Find all posts by this user
Quote this message in a reply
11-17-2017, 02:31 AM
Post: #31
RE: Change name for →Qπ - please suggest!
RATCOMP

Rational Composition -- all the results are essentially the composition of ->Q(X) with one of the following functions: 1(X) (identity), SQRT(X), EXP(X), LN(X), or PI(X) (multiplication by PI).

For a shorter name:

QFORM

Q for rational, and FORM because the program converts the numerical value into some form involving a rational value. Or perhaps RATFORM

If not QPI, then I would lean in favor of RATCOMP

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
11-17-2017, 06:25 AM
Post: #32
RE: Change name for →Qπ - please suggest!
Assuming that it finds the nearest approximation, perhaps something like QNEARF, or possibly just NEAR?
Find all posts by this user
Quote this message in a reply
11-17-2017, 10:41 AM
Post: #33
RE: Change name for →Qπ - please suggest!
if it's going to be built-in some day, it would be logical to assign it to the a b/c button in certain contexts. Currently, this is the approx and when you hit it again, it does the opposite = exact.
So, if you do exact(0.428571428571) it gives you 3/7 currently.

Hey, I just realized that QPI seems to be a more advanced exact() command.

Maybe we should just replace exact with the functionality in the QPI command. I added the qpif command suggested in Han's original post....wondering if maybe that's the version that gets called in CAS mode and the regular QPI gets called in Home mode.
Find all posts by this user
Quote this message in a reply
11-17-2017, 01:33 PM (This post was last modified: 11-17-2017 01:34 PM by Eddie W. Shore.)
Post: #34
RE: Change name for →Qπ - please suggest!
I like QPI (for consistency with the HP 48/49/50G family) or RAT (rationalize).
Visit this user's website Find all posts by this user
Quote this message in a reply
11-17-2017, 01:35 PM
Post: #35
RE: Change name for →Qπ - please suggest!
(11-17-2017 01:33 PM)Eddie W. Shore Wrote:  I like QPI or RAT (rationalize).

QPI (as the Han's version) is ok, and also RAT, yeah. However, if the problem is only the -> (in CAS I think) also Qπ could be ok...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
11-17-2017, 03:21 PM (This post was last modified: 11-19-2017 09:54 AM by compsystems.)
Post: #36
RE: Change name for →Qπ - please suggest!
The name must encompass a meaningful name for some functions that it performs

QPIRLNe: convert decimal to ℚ(p/q) or p/q*PI or SQRoot(p/q) or LN(p/q) or e^(p/q)

qpi_approx();
qpi_asqrtb();
qpi_out();
qpi_outsqrt();
qpi_real();
qpi_complex();
qpi_list();
qpi_root();
qpi_pi();
qpi_ln();
qpi_exp();
qpi_symb();

By tradition is QPI (hp48/50) but it does not report everything it can do, I propose QPIRLNe name from Q Quotient (fraction p/q) + or PI+ or ROOT+ or LN+ or e

Who else agrees with QPIRLNe?


PHP Code:
// QPI by Han Duong
// ported from QPI 4.3a for the HP48G/GX by Mika Heiskanen & Andre Schoorl

export qpiEXPLN:=100// max denom for exp(p/q) or ln(p/q)
export qpiMAXINT:=2^20// largest n allowed for sqrt(n)=a*sqrt(b)
export qpiDIGITS:=10// controls accuracy (best results at 9 or 10)

qpi_approx();
qpi_asqrtb();
qpi_out();
qpi_outsqrt();
qpi_real();
qpi_complex();
qpi_list();
qpi_root();
qpi_pi();
qpi_ln();
qpi_exp();
//qpi_symb();

EXPORT QPI(r)
BEGIN

  
case
    if 
TYPE(r)==0 then qpi_real(r); end;
    if 
TYPE(r)==1 then RETURN(r); end;
    if 
TYPE(r)==3 then qpi_complex(r); end;
    if 
TYPE(r)==6 then qpi_list(r); end;
    if 
TYPE(r)==8 then QPI(approx(r)); end;
    DEFAULT 
msgbox("Object type: " TYPE(r) + " not supported!");
  
end;

END;


qpi_real(r)
BEGIN
  local frac
;

  if 
r then 
    frac
:=qpi_approx(r);

    if 
frac(2)<100 then
      qpi_out
(frac);
    else
      
qpi_root(r,frac);
    
end;
  else
    RETURN(
0);
  
end;
END;


qpi_complex(c)
BEGIN
  local rpart
ipart;

  
rpart:=STRING(qpi_real(RE(c)));
  
ipart:=STRING(qpi_real(abs(IM(c))));

  if 
IM(c)>0 then
    expr
("'" rpart "+" ipart "*'");
  else
    
expr("'" rpart "-" ipart "*'");
  
end;

END;


qpi_list(l)
BEGIN
  local i
,n;

  
n:=SIZE(l);
  for 
i from 1 to n do
    
l(i):=QPI(l(i));
  
end;

  RETURN(
l);
  
END;


qpi_root(r,frac)
BEGIN
  local frac1
;

  if 
r^2<500001 then

    frac1
:=qpi_approx(r^2);
    if 
r<0 then frac1(1):=-frac1(1); end;
    
frac1(3):=1;
    if (
frac1(2)<1000) AND (frac1(2)<=frac(2)) then
      
if frac1(2)<10 then
        qpi_out
(frac1);
      else
        
qpi_pi(r,frac1);
      
end;
    else 
// sqrt denom not smaller
      
qpi_pi(r,frac);
    
end;    

  else 
// r^2>500000

    
qpi_pi(r,frac);

  
end// end_if r^2<500000
END;


qpi_pi(r,frac)
BEGIN
  local frac1
;

  if 
abs(r/pi)<101 then

    frac1
:=qpi_approx(r/pi);
    
frac1(3):=2;
    if (
frac1(2)<1000) AND (frac1(2)<=frac(2)) then
      
if frac1(2)<10 then
        qpi_out
(frac1);
      else
        
qpi_ln(r,frac1);
      
end;
    else 
// (r/pi) denom not smaller
      
qpi_ln(r,frac);
    
end;

  else 
// abs(r/pi)>100

    
qpi_ln(r,frac);

  
end// end_if abs(r/pi)<101
END;


qpi_ln(r,frac)
BEGIN
  local frac1
,tmp;

  
tmp:=e^(r);

  if 
tmp<1001 then

    
// check for LN(0)
    
if tmp then
      frac1
:=qpi_approx(tmp);
    else
      
frac1:=qpi_approx(MINREAL);
    
end;
    
frac1(3):=3;

    if (
frac1(1)*frac1(2)==1) OR (frac1(2)>qpiEXPLNthen

      qpi_exp
(r,frac);

    else

      if (
frac1(2)<=frac(2)) then
        
if frac1(2)<10 then
          qpi_out
(frac1);
        else
          
qpi_exp(r,frac1);
        
end;
      else
        
qpi_exp(r,frac);
      
end;

    
end// end_if p*q==1 or q>50

  
else // e^(r)>1000

    
qpi_exp(r,frac);

  
end// end_if e^(r)<1001
END;


qpi_exp(r,frac)
BEGIN
  local frac1
;

  if 
r<0 then
    qpi_out
(frac);
  else

    
frac1:=qpi_approx(LN(r));
    
frac1(3):=4;
    if 
frac1(2)>qpiEXPLN then
      qpi_out
(frac);
    else
      if 
frac1(2)<=frac(2then
        qpi_out
(frac1);
      else
        
qpi_out(frac);
      
end;
    
end;

  
end;
END;


// returns frac(t+1) where
// frac:={p/q, sqrt(p/q), p/q*pi, ln(p/q), e^(p/q)}
// and list:={p,q,t}
qpi_out(list)
BEGIN
  local s0
="("s1=")'";

  if list(
3)==1 then

    qpi_outsqrt
(list);

  else

    if list(
1)<0 then s0:="-" s0end;
    if list(
3then s1:=")" s1end;

    case
      if list(
3)==2 then s1:=")*π'"end;
      if list(
3)==3 then s0:="LN(" s0end;
      if list(
3)==4 then s0:="e^(" s0end;
    
end;

    
s0:="'" s0;

    if list(
2)==1 then
      expr
(s0 abs(list(1)) + s1);
    else
      
expr(s0 abs(list(1)) + "/" + list(2) + s1);
    
end;
  
end;
END;


qpi_outsqrt(list)
BEGIN
  local ab1
ab2;
  
local s0="'";

  if list(
1)<0 then s0:=s0+"-"end;

  
ab1:=qpi_asqrtb(abs(list(1)));
  
ab2:=qpi_asqrtb(list(2));

  if 
ab1(1)<>ab2(1then
    
if ab2(1)==1 then
      s0
:=s0 ab1(1) + "*";
    else
      
s0:=s0 "(" ab1(1) + "/" ab2(1) + ")*";
    
end;
  
end;

  
s0:=s0 "√(";

  if 
ab2(2)==1 then
    s0
:=s0 ab1(2);
  else
    
s0:=s0 ab1(2) + "/" ab2(2);
  
end;

  
expr(s0+")'");
END;


// returns {a,b} where n=a*sqrt(b)
qpi_asqrtb(n
BEGIN
  local div
,quo,rem,num,den,nodd;

  if 
n>qpiMAXINT then RETURN({1,n}); end;

  
div:=1;
  
num:=n;
  
den:=4;
  
nodd:=3;

  
repeat
    quo
:=IP(num/den);
    
rem:=num MOD den;

    if 
rem==0 then
      div
:=div*(IP(nodd/2)+1);
      
num:=quo
    else
      
nodd:=nodd+2;
      
den:=den+nodd;
    
end;
  
until (quo==0) OR (nodd>qpiMAXINTend

  RETURN({
div,num});
END;


// returns {p,q,0} where r=p/q
qpi_approx(r
BEGIN
  local num
,inum,den,iden;
  
local p0,q0,p1,q1,p2,q2;
  
local quo,rem;

  if 
NOT(rthen RETURN({0,1,0}); end;

  
num:=abs(r);
  
inum:=IP(num);
  
den:=1;

  while 
num-inum do
    
num:=num*10;
    
den:=den*10;
    
inum:=IP(num);
  
end;

  
iden:=den;

  
rem:=denden:=num
  
p1:=0p2:=1;
  
q1:=1q2:=0;

  
repeat
    p0
:=p1p1:=p2;
    
q0:=q1q1:=q2;
    
num:=denden:=rem;
    
quo:=IP(num/den);
    
rem:=num MOD den;
    
p2:=quo*p1+p0;
    
q2:=quo*q1+q0;
  
until 10^qpiDIGITS*abs(inum*q2-iden*p2)<iden*p2 end

  if (
r>0then
    
RETURN({p2,q2,0});
  else
    RETURN({
−p2,q2,0});
  
end;


END;

#cas
qpi_symb(f):=
begin
  local j
,n,g,r;
  if (
type(f) <> DOM_SYMBOLICthen return(f); end;

  
n:=dim(f)+1;

  for 
j from 2 to n do

    
g:=f[j];
    if (
type(g) == DOM_FLOATthen
      r
:=QPI(g);
      
f[j]:=r;
    
end;
    if (
type(g) == DOM_SYMBOLICthen
      r
:=qpif(g);
      
f[j]:=r;
    
end;
  
end;
  return(
f);
end;
#end 
Find all posts by this user
Quote this message in a reply
11-17-2017, 03:36 PM
Post: #37
RE: Change name for →Qπ - please suggest!
To Tim's point,

An unaware student, seeking an exact representation of these numbers might not quickly think of QPI as an applicable command name for this purpose. As a command name, QPI doesn't convey its purpose very well.

Command names that have some essence of their purpose have search advantages, and are more intuitive when encountered in programs. QPI could be part of the help description for historical context, but as a command name, it's not the best.
Find all posts by this user
Quote this message in a reply
11-17-2017, 03:43 PM
Post: #38
RE: Change name for →Qπ - please suggest!
(11-17-2017 03:36 PM)DrD Wrote:  An unaware student, seeking an exact representation of these numbers might not quickly think of QPI as an applicable command name for this purpose.

So, EXACT() should be appropriate for this purpose.
Find all posts by this user
Quote this message in a reply
11-17-2017, 03:50 PM
Post: #39
RE: Change name for →Qπ - please suggest!
(11-17-2017 03:43 PM)Didier Lachieze Wrote:  
(11-17-2017 03:36 PM)DrD Wrote:  An unaware student, seeking an exact representation of these numbers might not quickly think of QPI as an applicable command name for this purpose.

So, EXACT() should be appropriate for this purpose.

exact() currently already exists as a command. Moreover, it only converts to fractional form, unless I am mistaken. If we wish to use EXACT, (all uppercase, to be treated differently from all lowercase exact()) then it could work. However, there are many forms that will not be handled by QPI (at least not currently): SIN(2), 2+SQRT(3), 1/PI, etc. So EXACT seems to be overreaching as far as names go.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
11-17-2017, 03:55 PM (This post was last modified: 11-17-2017 04:00 PM by salvomic.)
Post: #40
RE: Change name for →Qπ - please suggest!
try with 2.30258509299 as result of approx(LN(10))

exact(2.30258509299) returns (bot Home and CAS) 1944167/844341
QPI(2.30258509299) and ->Qπ(2.30258509299) return LN(10).
Note: QPI both in Home and CAS, ->Qπ for now only in Home.

Onestly, I prefer the output of QPI, and I think we could keep both commands separated and for different goals...
However, maybe also a (all caps) EXACT() could be a good idea.

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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