login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for #358 EXPR does not handle conditional definitions revision 1 of 2

1 2
Editor:
Time: 2007/12/28 14:29:41 GMT-8
Note: Re: FIXED element in POLY INT

changed:
-
Define the following function:

\begin{axiom}
f(x|x<0)==-x**2
f(x)==x**2
\end{axiom}

Then, draw the function
\begin{axiom}
draw(f(x),x=-1..1)
\end{axiom}
Note that the function is compiled with 'Variable x -> Polynomial Integer', and the viewport shows the function 'x*x', even for 'x<0', where it should show '-x*x'.

The same holds when you eval the function:
\begin{axiom}
eval(f(x),x=-5)
\end{axiom}
Here, we should expect '-25'. And shouldn't
\begin{axiom}
f(x)
\end{axiom}
result in something similar to
\begin{axiom}
)display values f
\end{axiom}

Integration, therefore, also goes wrong,
\begin{axiom}
integrate(f(x),x=-5..5)
\end{axiom}
which should of course yield '0'. It would appear that in certain operations, when performing a function on 'f' (like 'draw', 'eval', 'integrate'), or when 'x' is not specified, it is assumed to be positive. After that, the actual value is filled in and this can therefore yield an erroneous result.

I use Version: Axiom 3.9 (September 2005) on gentoo (amd64).

<hr />

**On June 3, 2007 Bill Page wrote:**

An anonymous author wrote::

  Axiom is being inconsistent, and this is an interpreter bug!

In the Axiom programming language it is possible to avoid the
immediate evaluation of 'f(x)' in some contexts. For example
\begin{axiom}
[f(x) for x in -5..5]
\end{axiom}

but the Axiom interpreter does not treat $[\dots]$ as an operator or
even a generator. Perhaps this could be considered inconsistent.
In this regard the Aldor programming language is certainly more
general and more consistent.

But to be consistent with other parts of Axiom as it exists now it
is possible to write this in an equivalent "functional" style:
\begin{axiom}
map(f,expand(-5..5))
\end{axiom}


From anonymous Sun Jun 3 03:39:47 -0500 2007
From: anonymous
Date: Sun, 03 Jun 2007 03:39:47 -0500
Subject: numerical evaluation
Message-ID: <20070603033947-0500@wiki.axiom-developer.org>

This rewriting does not change the result or explain the difference in handling. 'map(f, ...)' is not exactly the same syntax as 'integrate(f(x), ...)'. I think the real reason for the failure of 'eval', 'integrate' is these functions are not programmed to handle conditionals in function definitions.

\begin{axiom}
h(x | x<=0) == -x^2
eval(h(x), x=-2)
integrate(h(x), x=-2..0)
integrate(h(x), x=-2.0..0.0)
\end{axiom}

If the interpreter is able to find another definition for h that is valid, it would have used it. Instead of compiling the function h, as in the handling of 'map(h, ...)', and which is what it might have done, the interpreter is trying to evaluate exactly, not numerically. Are there any numerical integration functions in Axiom? Indeed, how can I compute something like

\begin{axiom}
[h(x) for x in -1.0..0.0 by 0.5]
\end{axiom}

Must I manually translate an integer segment to a float segment (a la old Fortran)?

\begin{axiom}
[h(-1.0+0.5*i) for i in 0..2]
\end{axiom}


From billpage Sun Jun 3 12:13:47 -0500 2007
From: billpage
Date: Sun, 03 Jun 2007 12:13:47 -0500
Subject: Re: numerical evaluation
Message-ID: <20070603121347-0500@wiki.axiom-developer.org>

Anonymous wrote::

  I think the real reason for the failure of eval, integrate is these
  functions are not programmed to handle conditionals in function
  definitions.

No that is not correct. The function definition you have is incomplete.
Your 'h' is only defined for x<=0. So Axiom cannot evaluate this for
the value 'x' since
\begin{axiom}
x<=0
\end{axiom}
That is why it says: "The function h is not defined for the given
argument(s)." (Note: click on + axiom on the right to see the
output of the compiler.)

Anonymous wrote::

  the interpreter is trying to evaluate exactly, not numerically

Yes that is always true in Axiom. Axiom never makes an
approximation unless you specifically ask it to.

Anonymous wrote::

  Are there any numerical integration functions in Axiom?

Yes. For example search for 'romberg' in hyperdoc.

Anonymous wrote::

  Must I manually translate an integer segment to a
  float segment?

I do not know exactly what you mean by a "float segment"
but yes I think writing::

  [h(-1.0+0.5*i) for i in 0..2]

is sensible if that is the output that you want.

What you are calling a "float segment" might be something
for like an "interval" but that is a different story.


From anonymous Wed Jun 6 15:45:26 -0500 2007
From: anonymous
Date: Wed, 06 Jun 2007 15:45:26 -0500
Subject: SEG Float is a valid constructor
Message-ID: <20070606154526-0500@wiki.axiom-developer.org>
In-Reply-To: <20070603121347-0500@wiki.axiom-developer.org>

>No that is not correct. The function definition you have is incomplete. Your h is only defined for x<=0. So Axiom cannot evaluate >this for the value x since

I think Axiom is "stupid" to even think that in the definition of h, the x is symbolic as in POLY INT or EXPR INT. The function definition is complete as shown by the correct execution of $[$h(-1.0+0.5*i) for i in 0..2$]$. A function h is NOT the same as a value h(x) where x is a variable in EXPR INT. We should integrate h, not h(x). 

Since it is not related to this issue report, the discussion of
"float segments" has been moved to SandBoxFloatSegment. 


From billpage Wed Jun 6 16:33:52 -0500 2007
From: billpage
Date: Wed, 06 Jun 2007 16:33:52 -0500
Subject: Re: Axiom is "stupid"
Message-ID: <20070606163352-0500@wiki.axiom-developer.org>

Anonymous wrote::

  Axiom is "stupid" to even think that in the definition
  of h, the x is symbolic

In Axiom x, 1, and 1.0 are all equally symbolic. The distinction
between "symbolic" and "numeric" is not relevant. All of these
things are members of some domain or other and the Axiom
interpreter will make some assumptions unless you specify
explicitly which domains (e.g. in this case the assumed domains
are Variable(x), PositiveInteger, and Float, respectively).

Anonymous wrote::

  definition [ h(x | x<=0) == -x^2 ]is complete as shown 

No it is not. This is just a function prototype, not a 
function. The Axiom intetpreter automatically fills in the
missing information based on the context where you use this
prototype so what you get is the evaluation of a function
that was partly created by assumptions made by the Axiom
interpreter. These assumptions do not work when you call
h with something of type Variable(x).


From wyscc Thu Jun 7 05:03:55 -0400 2007
From: wyscc
Date: Thu, 07 Jun 2007 05:03:55 -0400
Subject: Functions and Segments
Message-ID: <20070606163352-0500@wiki.axiom-developer.org>

billpage wrote::

  Anonymous wrote::

    Axiom is "stupid" to even think that in the definition
    of h, the x is symbolic

  In Axiom x, 1, and 1.0 are all equally symbolic. The distinction
  between "symbolic" and "numeric" is not relevant.

I think anonymous' view is correct: a function is just a rule that assigns a 
value when given a value. The 'h' defined earlier (a function prototype as you 
call it) can only be interpreted with a source domain that has an order, a 
multiplication, and a negation. However, if 'x' is interpreted as a FIXED 
element in 'POLY INT', 'h' is no longer a function from 'POLY INT' to 'POLY INT' 
(unless you view 'h' as defining the substitution homomorphism on $Q[x]$ sending 
$x$ to $-x^2$; but that is not what we meant when we want to integrate 'h'). As 
far as calculus goes, we integrate a function, NOT a polynomial $h(x)$ with a 
FIXED indeterminate $x$ although by abuse of notation, we use the polynomial 
$h(x)$ to mean the function itself. Thus for Axiom to test $x < 0$ with $x$ as a 
FIXED interminate in $Q[x]$ in a function (or function prototype) definition 
is unwise no matter what context; x must be interpreted as a dummy variable 
(place holder) only.


From BillPage Sun Jun 10 22:57:39 -0500 2007
From: Bill Page
Date: Sun, 10 Jun 2007 22:57:39 -0500
Subject: Re: FIXED element in POLY INT
Message-ID: <20070610225739-0500@wiki.axiom-developer.org>

**wyscc** wrote: --
  <em>if x is interpreted as a FIXED element in POLY INT, h is no longer a
  function from POLY INT to POLY INT (unless you view h as defining the
  substitution homomorphism on $Q[x]$ sending $x$ to $x^2$; but that is
  not what we meant when we want to integrate h).</em>

The definition
\begin{axiom}
h(x | x<=0) == -x^2
h(x | x>0) == x^2
\end{axiom}

does not necessarily have anything to do with integration or
polynomials since we know nothing at all about what the domain
and co-domain of the function will be. If we had already
specified a signature such as::

  h:Float->Float

then we could be sure that integration is at least in principle
possible. But as it stands we only have part of the body of a
potential function, i.e. a function prototype.

In any case 'x' here is just a placeholder or dummy variable.

But given only the prototype, if in Axiom I write::

  h(w)

where 'w' was not previously defined then the interpreter starts
by assuming that 'w' is just a variable:
\begin{axiom}
w
\end{axiom}

But to interpret what is meant by 'w<=0', w>0,  - and w^2, after
a search of possibilities,  Axiom finds that it can coerce the
variable w to the a 'Polynomial Integer' where <= and > are
interpreted as lexical ordering and w^2 is given by w*w, as
multiplication of polynomials. It is not necessary to think
in terms of "substitution homomorphism".

Even when we specify a signature such as::

  h:Polynomial Integer -> Polynomial Integer

The 'x' on the lhs and the expression '-x^2' on the rhs of
== in the prototype for 'h' above is *not* a polynomial. It
remains a dummy variable as defined according to the semantics
of the Axiom programming language. But in this case the
prototype does define a mapping (not necessarily a homomorphism)
from polynomials into polynomials.

**wyscc** wrote: --
  <em>As far as calculus goes, we integrate a function, NOT a
  polynomial ... </em>

I agree. What we really would like to write is something like::

  integrate(h)

and we would expect the result to be another function. But
this can be very difficult for arbitrary piecewise functions.


Submitted by : (unknown) at: 2007-11-17T22:32:30-08:00 (17 years ago)
Name :
Axiom Version :
Category : Severity : Status :
Optional subject :  
Optional comment :

Define the following function:

axiom
f(x|x<0)==-x**2
Type: Void
axiom
f(x)==x**2
Type: Void

Then, draw the function

axiom
draw(f(x),x=-1..1)
axiom
Compiling function f with type Variable x -> Polynomial Integer
axiom
Compiling function %B with type DoubleFloat -> DoubleFloat 
   Graph data being transmitted to the viewport manager...
   FriCAS2D data being transmitted to the viewport manager...
LatexWiki Image(1)
Type: TwoDimensionalViewport?

Note that the function is compiled with Variable x -> Polynomial Integer, and the viewport shows the function x*x, even for x<0, where it should show -x*x.

The same holds when you eval the function:

axiom
eval(f(x),x=-5)
LatexWiki Image(2)
Type: Polynomial Integer

Here, we should expect -25. And shouldn't

axiom
f(x)
LatexWiki Image(3)
Type: Polynomial Integer

result in something similar to

axiom
)display values f Definition: 2 f (x | x < 0) == - x 2 f x == x

Integration, therefore, also goes wrong,

axiom
integrate(f(x),x=-5..5)
LatexWiki Image(4)
Type: Union(f1: OrderedCompletion? Expression Integer,...)

which should of course yield 0. It would appear that in certain operations, when performing a function on f (like draw, eval, integrate), or when x is not specified, it is assumed to be positive. After that, the actual value is filled in and this can therefore yield an erroneous result.

I use Version: Axiom 3.9 (September 2005) on gentoo (amd64).


On June 3, 2007 Bill Page wrote:

An anonymous author wrote:

  Axiom is being inconsistent, and this is an interpreter bug!

In the Axiom programming language it is possible to avoid the immediate evaluation of f(x) in some contexts. For example

axiom
[f(x) for x in -5..5]
axiom
Compiling function f with type Integer -> Integer
LatexWiki Image(5)
Type: List Integer

but the Axiom interpreter does not treat LatexWiki Image as an operator or even a generator. Perhaps this could be considered inconsistent. In this regard the Aldor programming language is certainly more general and more consistent.

But to be consistent with other parts of Axiom as it exists now it is possible to write this in an equivalent "functional" style:

axiom
map(f,expand(-5..5))
LatexWiki Image(6)
Type: List Integer

numerical evaluation --anonymous, Sun, 03 Jun 2007 03:39:47 -0500 reply
This rewriting does not change the result or explain the difference in handling. map(f, ...) is not exactly the same syntax as integrate(f(x), ...). I think the real reason for the failure of eval, integrate is these functions are not programmed to handle conditionals in function definitions.

axiom
h(x | x<=0) == -x^2
Type: Void
axiom
eval(h(x), x=-2)
axiom
Compiling function h with type Variable x -> Polynomial Integer 
   The function h is not defined for the given argument(s).
integrate(h(x), x=-2..0)
   The function h is not defined for the given argument(s).
integrate(h(x), x=-2.0..0.0)
   The function h is not defined for the given argument(s).

If the interpreter is able to find another definition for h that is valid, it would have used it. Instead of compiling the function h, as in the handling of map(h, ...), and which is what it might have done, the interpreter is trying to evaluate exactly, not numerically. Are there any numerical integration functions in Axiom? Indeed, how can I compute something like

axiom
[h(x) for x in -1.0..0.0 by 0.5] The lower bound in a loop must be an integer.

Must I manually translate an integer segment to a float segment (a la old Fortran)?

axiom
[h(-1.0+0.5*i) for i in 0..2]
axiom
Compiling function h with type Float -> Float
LatexWiki Image(7)
Type: List Float

Re: numerical evaluation --billpage, Sun, 03 Jun 2007 12:13:47 -0500 reply
Anonymous wrote:
  I think the real reason for the failure of eval, integrate is these
  functions are not programmed to handle conditionals in function
  definitions.

No that is not correct. The function definition you have is incomplete. Your h is only defined for x<=0. So Axiom cannot evaluate this for the value x since

axiom
x<=0
LatexWiki Image(8)
Type: Boolean

That is why it says: "The function h is not defined for the given argument(s)." (Note: click on + axiom on the right to see the output of the compiler.)

Anonymous wrote:

  the interpreter is trying to evaluate exactly, not numerically

Yes that is always true in Axiom. Axiom never makes an approximation unless you specifically ask it to.

Anonymous wrote:

  Are there any numerical integration functions in Axiom?

Yes. For example search for romberg in hyperdoc.

Anonymous wrote:

  Must I manually translate an integer segment to a
  float segment?

I do not know exactly what you mean by a "float segment" but yes I think writing:

  [h(-1.0+0.5*i) for i in 0..2]

is sensible if that is the output that you want.

What you are calling a "float segment" might be something for like an "interval" but that is a different story.

SEG Float is a valid constructor --anonymous, Wed, 06 Jun 2007 15:45:26 -0500 reply
No that is not correct. The function definition you have is incomplete. Your h is only defined for x<=0. So Axiom cannot evaluate >this for the value x since

I think Axiom is "stupid" to even think that in the definition of h, the x is symbolic as in POLY INT or EXPR INT. The function definition is complete as shown by the correct execution of LatexWiki Imageh(-1.0+0.5*i) for i in 0..2LatexWiki Image. A function h is NOT the same as a value h(x) where x is a variable in EXPR INT. We should integrate h, not h(x).

Since it is not related to this issue report, the discussion of "float segments" has been moved to SandBoxFloatSegment?.

Re: Axiom is "stupid" --billpage, Wed, 06 Jun 2007 16:33:52 -0500 reply
Anonymous wrote:
  Axiom is "stupid" to even think that in the definition
  of h, the x is symbolic

In Axiom x, 1, and 1.0 are all equally symbolic. The distinction between "symbolic" and "numeric" is not relevant. All of these things are members of some domain or other and the Axiom interpreter will make some assumptions unless you specify explicitly which domains (e.g. in this case the assumed domains are Variable(x), PositiveInteger?, and Float, respectively).

Anonymous wrote:

  definition [ h(x | x<=0) == -x^2 ]is complete as shown 

No it is not. This is just a function prototype, not a function. The Axiom intetpreter automatically fills in the missing information based on the context where you use this prototype so what you get is the evaluation of a function that was partly created by assumptions made by the Axiom interpreter. These assumptions do not work when you call h with something of type Variable(x).

Functions and Segments --wyscc, Thu, 07 Jun 2007 05:03:55 -0400 reply
billpage wrote:
  Anonymous wrote::

    Axiom is "stupid" to even think that in the definition
    of h, the x is symbolic

  In Axiom x, 1, and 1.0 are all equally symbolic. The distinction
  between "symbolic" and "numeric" is not relevant.

I think anonymous' view is correct: a function is just a rule that assigns a value when given a value. The h defined earlier (a function prototype as you call it) can only be interpreted with a source domain that has an order, a multiplication, and a negation. However, if x is interpreted as a FIXED element in POLY INT, h is no longer a function from POLY INT to POLY INT (unless you view h as defining the substitution homomorphism on LatexWiki Image sending LatexWiki Image to LatexWiki Image; but that is not what we meant when we want to integrate h). As far as calculus goes, we integrate a function, NOT a polynomial LatexWiki Image with a FIXED indeterminate LatexWiki Image although by abuse of notation, we use the polynomial LatexWiki Image to mean the function itself. Thus for Axiom to test LatexWiki Image with LatexWiki Image as a FIXED interminate in LatexWiki Image in a function (or function prototype) definition is unwise no matter what context; x must be interpreted as a dummy variable (place holder) only.

Re: FIXED element in POLY INT --Bill Page, Sun, 10 Jun 2007 22:57:39 -0500 reply
wyscc wrote:
if x is interpreted as a FIXED element in POLY INT, h is no longer a function from POLY INT to POLY INT (unless you view h as defining the substitution homomorphism on LatexWiki Image sending LatexWiki Image to LatexWiki Image; but that is not what we meant when we want to integrate h).

The definition

axiom
h(x | x<=0) == -x^2 Compiled code for h has been cleared. 1 old definition(s) deleted for function or rule h
Type: Void
axiom
h(x | x>0) == x^2
Type: Void

does not necessarily have anything to do with integration or polynomials since we know nothing at all about what the domain and co-domain of the function will be. If we had already specified a signature such as:

  h:Float->Float

then we could be sure that integration is at least in principle possible. But as it stands we only have part of the body of a potential function, i.e. a function prototype.

In any case x here is just a placeholder or dummy variable.

But given only the prototype, if in Axiom I write:

  h(w)

where w was not previously defined then the interpreter starts by assuming that w is just a variable:

axiom
w
LatexWiki Image(9)
Type: Variable w

But to interpret what is meant by w<=0, w>0, - and w^2, after a search of possibilities, Axiom finds that it can coerce the variable w to the a Polynomial Integer where <= and > are interpreted as lexical ordering and w^2 is given by w*w, as multiplication of polynomials. It is not necessary to think in terms of "substitution homomorphism".

Even when we specify a signature such as:

  h:Polynomial Integer -> Polynomial Integer

The x on the lhs and the expression -x^2 on the rhs of == in the prototype for h above is not a polynomial. It remains a dummy variable as defined according to the semantics of the Axiom programming language. But in this case the prototype does define a mapping (not necessarily a homomorphism) from polynomials into polynomials.

wyscc wrote:
As far as calculus goes, we integrate a function, NOT a polynomial ...

I agree. What we really would like to write is something like:

  integrate(h)

and we would expect the result to be another function. But this can be very difficult for arbitrary piecewise functions.