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 2 of 2

1 2
Editor: kratt6
Time: 2007/12/28 14:29:43 GMT-8
Note:

added:

From kratt6 Fri Dec 28 14:29:42 -0800 2007
From: kratt6
Date: Fri, 28 Dec 2007 14:29:42 -0800
Subject: 
Message-ID: <20071228142942-0800@axiom-wiki.newsynthesis.org>

Name: '#358 Variable is apparently always assumed to be positive?' => '#358 EXPR does not handle conditional definitions' 
Category: Axiom Mathematics => Axiom Library 

The problem, even with 'draw' is in the EXPR domain.  If you issue
\begin{axiom}
draw(f, -5..5)
\end{axiom}
the result will be fine.  However, if you give 'f(x)' as an argument, the library will internally convert it to INPUTFORM and then compile it as an expression, which fails of course...

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:

fricas
(1) -> f(x|x<0)==-x**2
Type: Void
fricas
f(x)==x**2
Type: Void

Then, draw the function

fricas
draw(f(x),x=-1..1)
There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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:

fricas
eval(f(x),x=-5)
There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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

fricas
f(x)
There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

result in something similar to

fricas
)display values f
CONCAT Definition: , f (x | x < 0) == - x**2 f x == x**2

Integration, therefore, also goes wrong,

fricas
integrate(f(x),x=-5..5)
There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. There are 3 exposed and 1 unexposed library operations named < having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op < to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named < with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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

fricas
[f(x) for x in -5..5]
There are no library operations named ** Use HyperDoc Browse or issue )what op ** to learn if there is any operation containing " ** " in its name. Cannot find a definition or applicable library operation named ** with argument type(s) Integer PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. Cannot compile map: f We will attempt to interpret the code. There are no library operations named ** Use HyperDoc Browse or issue )what op ** to learn if there is any operation containing " ** " in its name.
Cannot find a definition or applicable library operation named ** with argument type(s) Integer PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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:

fricas
map(f,expand(-5..5))
There are no library operations named ** Use HyperDoc Browse or issue )what op ** to learn if there is any operation containing " ** " in its name. There are no library operations named ** Use HyperDoc Browse or issue )what op ** to learn if there is any operation containing " ** " in its name. There are 66 exposed and 13 unexposed library operations named map having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op map to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named map with argument type(s) FunctionCalled(f) List(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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.

fricas
h(x | x<=0) == -x^2
Type: Void
fricas
eval(h(x), x=-2)
There are 2 exposed and 1 unexposed library operations named <= having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op <= to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named <= with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code. There are 2 exposed and 1 unexposed library operations named <= having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op <= to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named <= with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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

fricas
[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)?

fricas
[h(-1.0+0.5*i) for i in 0..2]
fricas
Compiling function h with type Float -> Float

\label{eq1}\left[ -{1.0}, \: -{0.25}, \:{0.0}\right](1)
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

fricas
x<=0
There are 2 exposed and 1 unexposed library operations named <= having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op <= to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named <= with argument type(s) Variable(x) NonNegativeInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

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 [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.

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 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.

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 Q[x] sending x to x^2; but that is not what we meant when we want to integrate h).

The definition

fricas
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
fricas
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:

fricas
w

\label{eq2}w(2)
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.

Name: #358 Variable is apparently always assumed to be positive? => #358 EXPR does not handle conditional definitions Category: Axiom Mathematics => Axiom Library

The problem, even with draw is in the EXPR domain. If you issue

fricas
draw(f, -5..5)
There are no library operations named ** Use HyperDoc Browse or issue )what op ** to learn if there is any operation containing " ** " in its name. There are no library operations named ** Use HyperDoc Browse or issue )what op ** to learn if there is any operation containing " ** " in its name. There are 10 exposed and 0 unexposed library operations named draw having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op draw to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named draw with argument type(s) FunctionCalled(f) Segment(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

the result will be fine. However, if you give f(x) as an argument, the library will internally convert it to INPUTFORM and then compile it as an expression, which fails of course...