axiom-mail
[Top][All Lists]

## Re: [Axiom-mail] Coersion error

 From: Martin Rubey Subject: Re: [Axiom-mail] Coersion error Date: Wed, 17 Jun 2009 09:04:34 +0200 User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux)

```Dear Arnold,

Arnold Doray <address@hidden> writes:

> I'm trying to create a set of orthogonal polynomials using the
> Gram-Schmidt process, but I hit a problem:
>
> dot(f,g) == integrate(f*g*x^2,x=-1..1)
> proj(f,g) == dot(f,g)*f/dot(f,f)
>
> p0 := 1
> p1 := x - proj(p0,x)
> p2 := x^2 - proj(p0,x^2) - proj(p1,x^2)
>
> p0 and p1 evaluate correctly, but p2 hits this error:

as a quick workaround (sorry for answering late), use

dot(f,g) == integrate(f*g*x^2,x=-1..1)::EXPR INT

instead.  I'm not yet sure how the "missing" coercion really should go,
since I don't think we want Expression OrderedCompletion Integer, but
rather OrderedCompletion Expression Integer...

(Waldek?)

> I've also tried to define p(n) as a recursive function like so:
>
> p(0) == 1
> p(n | n > 0) == x^n - sum(proj(p(k),x^n),k=0..n-1)

This is a common misconception.  sum takes as first argument an
expression, in your case proj(p(k),x^n), and then tries to "simplify"
this.

As always in Axiom (FriCAS, OpenAxiom), arguments are evaluated.  Thus,
Axiom tries to evaluate

proj(p(k),x^n)

Next step is (remember: arguments are always evaluated...) to evaluate
p(k).  So k is certainly not 0 (it's an Expression Integer), so we try
the other rule, i.e.,

p(n | n > 0) == x^n - sum(proj(p(k),x^n),k=0..n-1)

Thus, what you want is to use

p(n | n > 0) == x^n - reduce(+, [proj(p(k),x^n) for k in 0..n-1])

(1) -> proj(f,g) == dot(f,g)*f/dot(f,f)
Type: Void
(2) -> dot(f,g) == integrate(f*g*x^2,x=-1..1)::EXPR INT
Type: Void
(3) -> p(0) == 1
Type: Void
(4) ->   p(n | n > 0) == x^n - reduce(+, [proj(p(k),x^n) for k in 0..n-1])
Type: Void
(5) -> p 1
Compiling function dot with type (PositiveInteger,Fraction(
Polynomial(Integer))) -> Expression(Integer)
Compiling function dot with type (PositiveInteger,PositiveInteger)
-> Expression(Integer)
Compiling function proj with type (PositiveInteger,Fraction(
Polynomial(Integer))) -> Expression(Integer)
Compiling function dot with type (Expression(Integer),Fraction(
Polynomial(Integer))) -> Expression(Integer)
Compiling function dot with type (Expression(Integer),Expression(
Integer)) -> Expression(Integer)
Compiling function proj with type (Expression(Integer),Fraction(
Polynomial(Integer))) -> Expression(Integer)
Compiling function p with type Integer -> Expression(Integer)

(5)  x
Type: Expression(Integer)
(6) -> p 2

2
5x  - 3
(6)  -------
5
Type: Expression(Integer)

Hope this helps,

Martin

```

reply via email to