axiom-mail
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-mail] create a function


From: Renata Cereja
Subject: Re: [Axiom-mail] create a function
Date: Mon, 23 Mar 2009 20:17:09 -0300

Hi Martin,
 
Now, the function works. Thanks for the help and explanation.

2009/3/23 Martin Rubey <address@hidden>
Hi Cereja!

There is one "real" problem with your definition, and another one
that is trivial.

The "real" problem is that

        dx(x) == D(func,x)

cannot work.  (I'm guessing that you want to define a function that
returns the derivative of func evaluated at x.)  Actually, I'm not
sure what the interpreter would do with it in case it could compile
it.  I guess it would interpret it as a "rule", which is certainly
not what you had in mind.

The right way to do this is

        dx := D(func, x)
        m := eval(dx, x=P1.1)/(2*P1.2)

i.e., you define dx to be the derivative of func (i.e., dx is a
polynomial) and then you evaluate it using "eval".


The second, minor problem is that the interpreter is too stupid to
infer the types of m and ponto.  The workaround is to help the
interpreter by declaring them appropriately.

Below a function that seems to work.

Martin


AddPoints(func:POLY(INT),P1:LIST(INT),P2:LIST(INT)):LIST(FRAC(INT)) ==
  z:=1
  m: FRAC INT
  ponto: List FRAC INT
  if (P1.3 = 1) and (P2.3 = 1) then
     if (P1.1 < P2.1) then
        m:= (P2.2 - P1.2)/(P2.1 - P1.1)
     if (P2.1 < P1.1) then
        m:= (P1.2 - P2.2)/(P1.1 - P2.1)
     if (P1.1 = P2.1) and (P1.2 ~= P2.2) then
        z:=0
     if (P1.1 = P2.1) and (P1.2 = P2.2) then
        dx := D(func, x)
        m:= eval(dx, x=P1.1)/(2*P1.2)
     if (z = 1) then
        a := m^2
        xsoma := (-(P1.1 + P2.1 - a))
        ysoma := ((m*(xsoma-P1.1) + P1.2) * (-1))
        ponto := [xsoma,ysoma,z]
        ponto
     else
        [0,1,z]
  else
     if (P1.3 = 0) then
        ponto := P2
     else
        ponto := P1
     ponto




reply via email to

[Prev in Thread] Current Thread [Next in Thread]