PatrickT

Dr. Patrick T

2108 Reputation

18 Badges

16 years, 305 days

MaplePrimes Activity


These are replies submitted by PatrickT

FYI. In classic gui, the dots are not clearly visible, so it's best viewed in standard gui.

FYI. In classic gui, the dots are not clearly visible, so it's best viewed in standard gui.

yes, maple standard is slow to load and that's a serious issue -- I use maple classic as often as possible. Quite frankly, I couldn't be bothered with standard gui. Perhaps somewhat against the flow, I recommend classic, it should load very fast, try it.

yes, maple standard is slow to load and that's a serious issue -- I use maple classic as often as possible. Quite frankly, I couldn't be bothered with standard gui. Perhaps somewhat against the flow, I recommend classic, it should load very fast, try it.

very nice Axel, and it works on both classic and standard gui.

very nice Axel, and it works on both classic and standard gui.

I think the following adaptation (obtained by intuitive means) works on floats :

striptrail := proc(S)
    local i, j, L, s;
    s := convert(S, string);
    L := length(s);
    for i to L while s[i] = " " or s[i] = "0" do  end do;
    for j to L while s[-j] = " " do  end do;
    if 0 < searchtext(".", s) then
        for j from j to L while s[-j] = "0" do  end do
    end if;
    if s[-j] = "." then j := j + 1 end if;
    `if`(i + j < L + 2, parse(s[i .. -j]), 0)
end proc

striptrail(0.500);
striptrail(000.50);
striptrail(0);

                                 0.5


                                 0.5


                                  0

I think the following adaptation (obtained by intuitive means) works on floats :

striptrail := proc(S)
    local i, j, L, s;
    s := convert(S, string);
    L := length(s);
    for i to L while s[i] = " " or s[i] = "0" do  end do;
    for j to L while s[-j] = " " do  end do;
    if 0 < searchtext(".", s) then
        for j from j to L while s[-j] = "0" do  end do
    end if;
    if s[-j] = "." then j := j + 1 end if;
    `if`(i + j < L + 2, parse(s[i .. -j]), 0)
end proc

striptrail(0.500);
striptrail(000.50);
striptrail(0);

                                 0.5


                                 0.5


                                  0

testing strip:

strip("0.5000");

                                 ".5"

testing strip:

strip("0.5000");

                                 ".5"

I think you may find the procedure you're looking for in the following code:

http://ckw.phys.ncku.edu.tw/public/pub/src/pgm/Maple8/Maple%20Programming/logplots.mpl

it goes under the name of "strip", see below.

WARNING: Untested.

Copied for your convenience:

    # The next 2 procs are for finding the smallest length string to represent a number for 
    # use as a tickmark.
 
    # Strip leading and trailing blanks and 0 and trailing "." from S  
    strip:= proc(S)
       local i,j, L;
       L:= length(S);
       for i to L while S[i]=" " or S[i]="0" do od;
       for j to L while S[-j]=" " do od;
       # Only strip trailing 0 if there's a dec. pt.
       if searchtext(".", S) > 0 then
          for j from j to L while S[-j]="0" do od
       fi;
       if S[-j]="." then j:= j+1 fi;
       # if everything was stripped, make it 0
       `if`(i+j < L+2, S[i..-j], "0") 
    end proc; 
 
    # Compare various string representations of X and return the shortest and neatest.
    minstring:= proc(X::numeric, digs::nonnegint)
       local x, S, T, man, sign, exp, i, j, len_S, Digs;
       Digs:= `if`(nargs=2, digs, 1);  #default 1 digit after dec. pt.
       # Put into sci. notation and split into mantissa, sign of exponent, and exponent
       man, sign, exp:= sscanf(sprintf("%.*e", Digs, X), "%[^e]e%[+-]%[^e]")[];
       # Strip trailing 0 and "." from mantissa. 
       man:= strip(man);
       # Discard "+"; strip leading 0 from exponent.
       S:= cat(`if`(man="1", "", man), "e", `if`(sign="+", "", "-"), strip(exp));
       len_S:= length(S);
       x:= parse(man)*10^(parse(cat(sign,exp)));
       if x::integer then T:= sprintf("%d", x)
       else
          # Put into floating pt. form with same string length.
          T:= strip(sprintf("%.*f", max(Digs, len_S), x));
          # If floating pt is 0, there was probably too much truncation
          if parse(T) = 0 and X<>0 then return S fi;
       fi;
       # Give priority to floating pt if they are same length
       `if`(len_S < length(T), S, T)
    end proc;

I think you may find the procedure you're looking for in the following code:

http://ckw.phys.ncku.edu.tw/public/pub/src/pgm/Maple8/Maple%20Programming/logplots.mpl

it goes under the name of "strip", see below.

WARNING: Untested.

Copied for your convenience:

    # The next 2 procs are for finding the smallest length string to represent a number for 
    # use as a tickmark.
 
    # Strip leading and trailing blanks and 0 and trailing "." from S  
    strip:= proc(S)
       local i,j, L;
       L:= length(S);
       for i to L while S[i]=" " or S[i]="0" do od;
       for j to L while S[-j]=" " do od;
       # Only strip trailing 0 if there's a dec. pt.
       if searchtext(".", S) > 0 then
          for j from j to L while S[-j]="0" do od
       fi;
       if S[-j]="." then j:= j+1 fi;
       # if everything was stripped, make it 0
       `if`(i+j < L+2, S[i..-j], "0") 
    end proc; 
 
    # Compare various string representations of X and return the shortest and neatest.
    minstring:= proc(X::numeric, digs::nonnegint)
       local x, S, T, man, sign, exp, i, j, len_S, Digs;
       Digs:= `if`(nargs=2, digs, 1);  #default 1 digit after dec. pt.
       # Put into sci. notation and split into mantissa, sign of exponent, and exponent
       man, sign, exp:= sscanf(sprintf("%.*e", Digs, X), "%[^e]e%[+-]%[^e]")[];
       # Strip trailing 0 and "." from mantissa. 
       man:= strip(man);
       # Discard "+"; strip leading 0 from exponent.
       S:= cat(`if`(man="1", "", man), "e", `if`(sign="+", "", "-"), strip(exp));
       len_S:= length(S);
       x:= parse(man)*10^(parse(cat(sign,exp)));
       if x::integer then T:= sprintf("%d", x)
       else
          # Put into floating pt. form with same string length.
          T:= strip(sprintf("%.*f", max(Digs, len_S), x));
          # If floating pt is 0, there was probably too much truncation
          if parse(T) = 0 and X<>0 then return S fi;
       fi;
       # Give priority to floating pt if they are same length
       `if`(len_S < length(T), S, T)
    end proc;

do you mean that you cannot in advance know how to set displayprecision? for the purpose of removing zeros only, yes you are right. As I said, my suggestion does not directly answer your question, but I thought perhaps you were not so much concerned with removing zeros as cutting down on the display of floats.

I was wrong -- displayprecision works in classic but not in standard, I get this with Maple 13/Classic (while I get the same as you with Standard):

interface(displayprecision=1):
evalf(3/2);
evalf(3.02);
evalf(3.76);

                                 1.5


                                 3.0


                                 3.8

do you mean that you cannot in advance know how to set displayprecision? for the purpose of removing zeros only, yes you are right. As I said, my suggestion does not directly answer your question, but I thought perhaps you were not so much concerned with removing zeros as cutting down on the display of floats.

I was wrong -- displayprecision works in classic but not in standard, I get this with Maple 13/Classic (while I get the same as you with Standard):

interface(displayprecision=1):
evalf(3/2);
evalf(3.02);
evalf(3.76);

                                 1.5


                                 3.0


                                 3.8

let me add that

interface(displayprecision=1)

works in both standard and classic gui.

EDIT. let me add that NO, it doesn't seem to work in standard gui.

First 61 62 63 64 65 66 67 Last Page 63 of 93