Axel Vogt

5936 Reputation

20 Badges

20 years, 257 days
Munich, Bavaria, Germany

MaplePrimes Activity


These are replies submitted by Axel Vogt

plot(1/(cos(x)^2), x=0 .. 5*Pi*(1/4), y= 0..6);

x^3 = - 0.008 has 3 solutions, 2 of them are imaginary, 1 is real
and you want especially one of them
see the 'surd' command (which is a bit difficult to follow in the help pages):

"Note the differences among the outputs of the surd, ^, and root commands":

(-8.0)^(1/3); root(-8.0, 3); surd(-8.0, 3);;
                     1.000000000 + 1.732050807 I
                     1.000000000 + 1.732050807 I
                             -2.000000000
For plotting: Maple does not plot imaginary number, if not been explicitely told like
plot( [Re(root(x,3)),Im(root(x,3))], x= -1 ..1, color=[red, blue]);
 

here I also prefer to have the representants with positive sign ... as usual in Math

May be the following is towards what you have in mind, I once did that
in Visual Basic (for Excel to get values for negatives more exact), it
should be understandable: to get exp(x) one takes a presentation in
base 2, for higher powers one uses stored, pre-computed values and for
the rest - which is close to 0 - the Taylor series should do.

So it is done by a quite brute argument reduction.

  Attribute VB_Name = "Modul2"
  Option Explicit
  Option Base 0
  
  Function ExpExcel(x As Variant) As Variant
  ExpExcel = CStr(CDec(Exp(CDec(x)))) ' hat nur 15 Stellen
  End Function
  
  Function localExp(x As Variant) As Variant
  Dim i, j As Integer
  Dim absx As Variant
  Dim intx, fracx As Variant
  Dim binx(0 To 5) As Integer
  'Dim eps(0 To 5) As Integer
  Dim z, b, pow As Integer
  Dim v(0 To 6) As Variant
  Dim expintx As Variant
  Dim F(0 To 32) As Variant
  Dim sum As Variant
  Dim tst
  
  If (0 < x) Then
    localExp = Exp(x)
    Exit Function
  End If
  If (x <= -64) Then
    localExp = Exp(x)
    Exit Function
  End If
  
  ' -64 < x <= 0
  
  pow = Int(5)
  
  v(0) = CDec(0.367879441171442) + CDec(0.3215955237702 * 0.000000000000001)
  v(1) = CDec(0.135335283236612) + CDec(0.691893999495 * 0.000000000000001)
  v(2) = CDec(0.018315638888734) + CDec(0.1802937180213 * 0.000000000000001)
  v(3) = CDec(0.000335462627902) + CDec(0.5118388213891 * 0.000000000000001)
  v(4) = CDec(0.000000112535174) + CDec(0.7192591145138 * 0.000000000000001)
  v(5) = CDec(0.000000000000012) + CDec(0.6641655490942 * 0.000000000000001)
  v(6) = CDec(0#) + CDec(0.0000000000002 * 0.000000000000001)
  
  absx = -CDec(x)
  intx = Int(absx)
  fracx = CDec(absx - intx)
  
  ' binary
  z = intx
  b = 32 ' Int(2 ^ pow)
  tst = ""
  expintx = CDec(1)
  For i = pow To 0 Step -1
    binx(i) = Int(z / b)
    If (binx(i) = 1) Then
      expintx = expintx * CDec(binx(i)) * v(i)
    End If
    'tst = tst & CStr(i) & ": " & CStr(binx(i)) & " "
    z = z - binx(i) * b
    b = Int(b / 2)
    'tst = tst & CStr(binx(i))
  Next i
  'MsgBox (tst)
  
  F(0) = CDec(1)
  For i = 1 To 32
    F(i) = -fracx * CDec(F(i - 1)) / CDec(i) ' Mist: 7<a: berechnen!
    'sum = sum + F(i) * h ^ i
  Next i
  
  'Horner Form
  sum = CDec(0)
  For i = 0 To 32
    sum = CDec(F(32 - i) + sum)
  Next i
  
  
  localExp = CStr(expintx * sum)
  
  End Function

CDec is a data type, which is more precise than usual floats, but the
use is a bit limited - especially one has to convert to strings to see
it in full length in Excel sheets.
May be the following is towards what you have in mind, I once did that
in Visual Basic (for Excel to get values for negatives more exact), it
should be understandable: to get exp(x) one takes a presentation in
base 2, for higher powers one uses stored, pre-computed values and for
the rest - which is close to 0 - the Taylor series should do.

So it is done by a quite brute argument reduction.

  Attribute VB_Name = "Modul2"
  Option Explicit
  Option Base 0
  
  Function ExpExcel(x As Variant) As Variant
  ExpExcel = CStr(CDec(Exp(CDec(x)))) ' hat nur 15 Stellen
  End Function
  
  Function localExp(x As Variant) As Variant
  Dim i, j As Integer
  Dim absx As Variant
  Dim intx, fracx As Variant
  Dim binx(0 To 5) As Integer
  'Dim eps(0 To 5) As Integer
  Dim z, b, pow As Integer
  Dim v(0 To 6) As Variant
  Dim expintx As Variant
  Dim F(0 To 32) As Variant
  Dim sum As Variant
  Dim tst
  
  If (0 < x) Then
    localExp = Exp(x)
    Exit Function
  End If
  If (x <= -64) Then
    localExp = Exp(x)
    Exit Function
  End If
  
  ' -64 < x <= 0
  
  pow = Int(5)
  
  v(0) = CDec(0.367879441171442) + CDec(0.3215955237702 * 0.000000000000001)
  v(1) = CDec(0.135335283236612) + CDec(0.691893999495 * 0.000000000000001)
  v(2) = CDec(0.018315638888734) + CDec(0.1802937180213 * 0.000000000000001)
  v(3) = CDec(0.000335462627902) + CDec(0.5118388213891 * 0.000000000000001)
  v(4) = CDec(0.000000112535174) + CDec(0.7192591145138 * 0.000000000000001)
  v(5) = CDec(0.000000000000012) + CDec(0.6641655490942 * 0.000000000000001)
  v(6) = CDec(0#) + CDec(0.0000000000002 * 0.000000000000001)
  
  absx = -CDec(x)
  intx = Int(absx)
  fracx = CDec(absx - intx)
  
  ' binary
  z = intx
  b = 32 ' Int(2 ^ pow)
  tst = ""
  expintx = CDec(1)
  For i = pow To 0 Step -1
    binx(i) = Int(z / b)
    If (binx(i) = 1) Then
      expintx = expintx * CDec(binx(i)) * v(i)
    End If
    'tst = tst & CStr(i) & ": " & CStr(binx(i)) & " "
    z = z - binx(i) * b
    b = Int(b / 2)
    'tst = tst & CStr(binx(i))
  Next i
  'MsgBox (tst)
  
  F(0) = CDec(1)
  For i = 1 To 32
    F(i) = -fracx * CDec(F(i - 1)) / CDec(i) ' Mist: 7<a: berechnen!
    'sum = sum + F(i) * h ^ i
  Next i
  
  'Horner Form
  sum = CDec(0)
  For i = 0 To 32
    sum = CDec(F(32 - i) + sum)
  Next i
  
  
  localExp = CStr(expintx * sum)
  
  End Function

CDec is a data type, which is more precise than usual floats, but the
use is a bit limited - especially one has to convert to strings to see
it in full length in Excel sheets.

that's what I guessed and thus said "a subsequent use has a chance to be numerical difficult as well"

however you should have a new application in mind and as thus you always will be asked, how it compares
to existing ones, which should be achived at least as limiting situation and give examples for standarized
situations - can you do that given the supposed constant?

that's what I guessed and thus said "a subsequent use has a chance to be numerical difficult as well"

however you should have a new application in mind and as thus you always will be asked, how it compares
to existing ones, which should be achived at least as limiting situation and give examples for standarized
situations - can you do that given the supposed constant?

For me x modulo n is a kind of abuse anyway, as it means to
choose something from a set, the equivalence class. 

But since one does it for rationals as well and there seems
to be no good way to work with sets - why not ...

However it leads to the confusing discussion what to do with
rational functions as the thread about 'eval' shows.

For the ring or group definition Z ---> Z / nZ my view of x mod n is 
to choose *the* representant in the integer interval 0 ... abs(n)-1,
while for n=0 there is nothing to choose.

Why is it a problem to define it that way? It can only be some,
if one insists in viewing at it as 'division with reminder', but
in Algebra you work beyond that (just use it, if it applies).


PS: especially I dislike negative representants.

It has no background, I converted using Paint Shop with "GIF87A non-interlaced" as file format
the zipped original is appended (file format can be seen as first entry using a text editor).

It only got a background through the board here (a bit unreasonable).

Using Paint (Version 5.1 coming with WIN XP) shows it in white as well.


Updates & Microsoft ... I do avoid it as far as possible (at home) and so far I am not aware of
good reasons, why SP3 would give me something essentially better. It took me some effort
to kick off several standards in XP to feel better and I am afraid of re-doing after an upgrade
(or worse: side effects). And I am not sure, whether the tools I need for cleaning up XP would
be available for SP3 (for example "xp antispy" or "clearprog"). And I do not want to have a new
Internet Explorer (which I almost never use) or mailer setting or similar. Or indexing switched
on again.

More or less my odd thinking is that security holes in MS exist in new versions as well - but
new attacks will try that, while old ones meanwhile essentially are healed through tools. And
avoiding MS for some standard file types (like pictures, videos etc) is part of that for me :-)

Download 102_alec_wmf_display_problem.zip
View file details

It was in a standard document (behaviour does not depend on saved
or fresh one) using M12 on Win XP SP2 using a conventional PC with
TFT (connected analog, no special graphical card, not a 'wide' one).
Resolution is 1280*1024 in 32 Bit with larger font display, 113 dpi.
MS Office is a small version 2000.

My standard viewer is ACDC (which blurrs a bit), never from Microsoft.

The exported image has size 610*610 and uses 4 colors. I converted
this wmf to gif and it looks like it appears for me as in Maple -
and I do not have the problem with the 'shifted point', it is only
shifted due to the code. In format png it is ok as well.

Maple certainly uses local settings and the graphical subsystem.


Find the gif below, converted from the wmf.

Alec,

yes, the uploaded file (just repeated the download). May be a problem with your viewer?

Gruß

 

Edited: executing your code (from the initial post) in M12 and exporting as wmf is OK as
well (w.r.t. colors, however blurred and ~ 1.4 MB)

looked at it in PaintShop and ACDC (both older versions): white background, red line,
and could even convert it to a *.gif (which only needs 10% of size)

nice sense of humor :-)

for licensing: that open source licensing is a pain i.t.a. for commercial companies, for
every piece of shit you will need a laywer then and documentation or maintanance is
something to be thought before as well

SAGE is a bit of exception, I think - if you look at the GNU GSL you see a kind of converse
(certainly it is carefully maintained): if you are a Windows user you are left alone ...

BTW: I think it is already non-trivial to be sure, that you can provide a commercial interface
from a commercial SW to a GPLed SW *without* opening beyond the interface.

But personally you are free to give an interface Maple <---> SAGE.

 

Still not quite understand the origin of the question ...

nice sense of humor :-)

for licensing: that open source licensing is a pain i.t.a. for commercial companies, for
every piece of shit you will need a laywer then and documentation or maintanance is
something to be thought before as well

SAGE is a bit of exception, I think - if you look at the GNU GSL you see a kind of converse
(certainly it is carefully maintained): if you are a Windows user you are left alone ...

BTW: I think it is already non-trivial to be sure, that you can provide a commercial interface
from a commercial SW to a GPLed SW *without* opening beyond the interface.

But personally you are free to give an interface Maple <---> SAGE.

 

Still not quite understand the origin of the question ...

Once I learned from Carl Devore, that 'tryhard' is a master due to Gaston Gonnet.
So it is unlikely to be touched (there is the German word "Verschlimmbessern", it
means to make things worse by trying to improve). And 'array' vs. 'Array' is not
a bug.

But one can use it off the package in several cases. Here is something taken from
an old 'discussion' between Carl Devore & Robert Israel at the Maple newsgroup:

  Tryhard:= proc(expr)
  global E_in_Tryhard;
  subs(pow= `^`,
    codegen[optimize](subs(E_in_Tryhard= expr, ()-> E_in_Tryhard), tryhard))()
  end proc;

Use it with some care (it will not work on diff, int, limit - one needs the inert
forms D, Int and Limit and it certainly has other limitation, which I do not know,
besides things in the core of 'tryhard', may be even bugs).

In *any* case I would try simplify/size before using that (as it is maintained).

If you think it helps you than you can use it as follows (in the uploaded sheet):

  stampa:=map(simplify, stampa,size): 
  eval(stampa): map(length,%);

  stampa:=map(Tryhard,stampa): map(length, stampa);

                          [1903    474    0]
                          [                ]
                          [1378    709    0]
                          [                ]
                          [1193    414    0]


Note that a larger length does not mean higher complexity. After a re-run we have:

  tmp:=stampa[3,1]: codegen[cost](tmp);

    97 multiplications + 2 divisions + 35 additions + 14 functions + 59 subscripts

  tmp:=simplify(tmp,size): codegen[cost](tmp);

    97 multiplications + 2 divisions + 35 additions + 14 functions + 59 subscripts

  tmp:=Tryhard(tmp): codegen[cost](tmp);

    84 multiplications + 2 divisions + 33 additions + 51 subscripts+ 10 functions


The main improvement *may* be by function calls. But one would have to look at it.


A personal remark: probably you expect a bit to much from a CAS and ignore some
of the ability of compilers: they may *destroy or improve* what you feed them by
automatic inputs - which you do through hundreds of procs. Actually that means
that you provide code, that never has been tested - it just has been produced.
It is like blind flying. For example you will *never* have any impression about
the numerical stability, speed is not the glory. 

You may wish to think about the whole approach. Really.
First 168 169 170 171 172 173 174 Last Page 170 of 209