|
|
last edited 11 years ago by test1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ||
Editor: test1
Time: 2013/07/31 16:40:26 GMT+0 |
||
Note: |
changed: - "**" : (%, NonNegativeInteger) -> % "^" : (%, NonNegativeInteger) -> % changed: - "**" : (%, Integer) -> % "^" : (%, Integer) -> %
Symbolic Integers
A simple form of symbolic computation using just Variable and Integer.
(1) -> a:Union(Variable a,Integer)
b:Union(Variable b,Integer)
c:=a*3-b*2
(1) |
p:UP(x,Integer):=x*2-7
(2) |
pc := p c
(3) |
f(x)==x^3-x^2+1
fb := f b
Compiling function f with type Variable(b) -> Polynomial(Integer)
(4) |
a:=1
(5) |
b:=-3
(6) |
c
(7) |
eval(pc,['a=a, 'b=b])
(8) |
eval(c,['a=a, 'b=b])
(9) |
eval(fb,['a=a, 'b=b])
(10) |
a:=3.14 -- not permitted!
Cannot convert right-hand side of assignment 3.14
to an object of the type Union(Variable(a),Integer) of the left-hand side.
For more complex cases it is necessary to define a new domain of "indeterminants". These are symbols and unevaluated expressions that can be evaluated at a later time. This domain is modeled after InputForm which provides all of the basic functionality.
)abbrev domain INDET Indeterminant ++ Description: ++ This domain provides basic support for symbols and unevaluated expressions ++ Based on InputForm -- Author: Bill Page Indeterminant(): Join(SExpressionCategory(String,Symbol, Integer, DoubleFloat, OutputForm), ConvertibleTo SExpression) with eval: % -> Any ++ eval(f) evaluates f with current values of symbols "+" : (%, %) -> % ++ \spad{a + b} "-" : (%, %) -> % ++ \spad{a - b} "-" : % -> % ++ \spad{-a} "*" : (%, %) -> % ++ \spad{a * b} "/" : (%, %) -> % ++ \spad{a / b} "^" : (%, NonNegativeInteger) -> % ++ \spad{a ** b} "^" : (%, Integer) -> % ++ \spad{a ** b} coerce : Integer -> % == SExpression add Rep := SExpression
eval x == interpret(x pretend InputForm)
coerce(x:Integer):% == convert(x) coerce(x:%):OutputForm == expr x
convert(x:%):SExpression == x pretend SExpression convert(x:DoubleFloat):% == convert(x)$Rep
s1 + s2 == convert [convert("+"::Symbol),s1, s2]$List(%)
s1 - s2 == convert [convert("-"::Symbol),s1, s2]$List(%)
_-(s1) == convert [convert("-"::Symbol),s1]$List(%)
s1 * s2 == convert [convert("*"::Symbol),s1, s2]$List(%)
s1:% ^ n:Integer == convert [convert("^"::Symbol),s1, convert n]$List(%)
s1:% ^ n:NonNegativeInteger == s1 ^ (n::Integer)
s1 / s2 == convert [convert("/"::Symbol),s1, s2]$List(%)
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/2122500948687555929-25px002.spad using old system compiler. INDET abbreviates domain Indeterminant ------------------------------------------------------------------------ initializing NRLIB INDET for Indeterminant compiling into NRLIB INDET
>> System error: invalid number of arguments: 5
Symbolic Matrices
)clear all
All user variables and function definitions have been cleared.
m:Union(Indeterminant,Matrix Integer)
You cannot now use Indeterminant in the context you have it.
)clear all
All user variables and function definitions have been cleared.
d: Union(Variable d,Float)
d*2
(11) |
will be problematic, and the assignment between symbolic integers is not allowed.
a: Union(Variable a,Integer)
b: Union(Variable b,Integer)
b:=aI agree that the type
a is declared as being in Union(Variable(a),Integer) but has not been given a value.
Union(Variable d,Integer)
alone is not
sufficient for symbolic computation. But although it might look
strange, in fact a result of Polynomial Integer
for 2*d
is
not really a problem. Remember that the use of Integer
in
Polynomial Integer
does not mean that evaluation of the
polynomial yields an Integer
- it means only that the domain
of the coefficients of the polynomial are integers (i.e. that
2 is an integer), it says nothing about 'd':
p:=2*d
(12) |
eval(p,d=3.14)
(13) |
But there is still a problem since I can write:
a:Union(Variable a,Integer)
a:=3.14
Cannot convert right-hand side of assignment 3.14
to an object of the type Union(Variable(a),Integer) of the left-hand side.
and Axiom does not complain about the eval
request because
as far as Polynomial Integer
is concerned d
is just a
Symbol.
In the case of the example Indeterminant
domain, evaluation
of symbolic expressions is always delayed so an appropriate
eval
operation could be defined that properly respects the
type.
b:=a
should mean. Does it mean that Variable(b)
is to be assigned the Symbol a
? If so then I think the type should
admit this possibility. E.g.
c:Union(Variable(c),Symbol)
c:=a
(14) |
PS: In the light of polynomial, (2d) is a non-zero polynomial, so that it's always safe to write (1/(2d)), but it's actually non-safe to do it in the domain of float(or integer).
b:=a is meaningless, of course. But there are many scenarios
)clear all
All user variables and function definitions have been cleared.
i:=10
(15) |
a: Union(Variable a,Integer)
b: Union(Variable b,Integer)
b:= (i>0=>1; a)
(16) |
which is meaningful.
Be careful,Expression Float
may not be what you think it is.
In Axiom Expression R
is a domain constructor which extends
rational functions with coefficients in R (Fraction Polynomial R)
by adding a set of common operators, e.g. sin
, sqrt
, etc.
Again the appearance of Float
here does not say anything
specific about the result of evaluating the expression or even
the values that can be associated with it's generators. I do
not know why one might prefer Expression Float
over
Polynomial Float
or even Polynomial Integer
.
We wish to place a restriction on the possible values that
certain symbols can take. Such symbols and expressions formed
from them certainly cannot live in a numeric domain such as
Float. Except in certain circumstances (mentioned previously)
I think a domain such as a:Union(Variable(a),Float)
and the
domains to which it can be coerced (such as Polynomial,
Expression, ...) does already represent such a symbolic
expressions fairly well.
But 1) What is Symbolic Float
? Can you give a description?
And 2) How can I express the concept of "non-zero polynomial"
in Axiom? I might use a domain that does not include zero for
example a:Union(Variable(a),PositiveInteger)
but there is no
general domain of NonZero
anything.
Ok, back to my own point. what's the justification of that the multiplication of two floats returns a polynomial float? Even the value is unknown, the type is certain, and float is closed under multiplication, so the return must be still a float, right?
AFAIK, Axiom currently support only polynomials with coefficients of known values. Then the only zero-polynomial(Integer) is 0$Polynomial Integer, others are non-zero polynomials.
The multiplication of a Float and some unknown symbolic value must produce a symbolic expression of some kind. If we know that the currently unknown symbolic value can only take values from Float, then we can deduce from knowledge of multiplication in Float that the value of the symbolic expression representing the multiplication of a Float with this unknown symbolic value must also only take values from Float.But Axiom currently does not have any domain whose values are symbolic expressions which only evaluate to values in some specific domain. Polynomial is one of the existing domains in Axiom whose values are symbolic expressions (of a very specific type). Symbolic expression in the domain Expression are more general but still rather restricted in form. Finally there is InputForm which consists of fully unevaluated expressions of the most general form allowed in Axiom.
Perhaps what you have called "Symbolic Float" could be implemented as an extension of the domain I called "Indeterminant" above.
But a polynomial containing at least one monomial term is symbolic. Certain combinations of values substituted for the symbols may result in zero (such values are called is "solution").
If a value of 0 is subsituted for d in this "non-zero polynomial"
then in what sense is 1/(2d)
safe?
For the second question: Yes, polynomial (x-1) might be evaluated to 0 (all of Integer,Float,Complex?), but this doesn't change the matter of (x-1) is not a zero-polynomial. Well, do you think (x**2-1)/(x-1) = (x+1) is legal and guaranteed in the domain of polynomial? But it's not in the domain of Float/Integer. You don't want to modify the rule of polynomial to accommodate this, right?
The polynomial 0, which may be considered to have no terms at all, is called the zero polynomial. (from http://en.wikipedia.org/wiki/Polynomial)
"But Axiom currently does not have any domain whose values are symbolic expressions which only evaluate to values in some specific domain" This statement is not the justification of picking one domain that is closest to the requirement and using it, but a justification of making one.Domain "Indeterminant" is a good example for this, thanks.
Yes,x:Polynomial Float
p:=(x^2-1)/(x-1)
(17) |
eval(p,x=1)
(18) |
is certainly legal and safe in the domain of polynomial
where the result is required to be a polynomial although it
seems that Axiom is being careful to give the result type
as Fraction Polynomial Float
and not automatically
Polynomial Float
.
Do you agree that it is not safe if all we know about x
is that it is a symbol which can be replaced with a Float?
In this case a domain like Indeterminant
can deal with it.
)library INDET
Indeterminant is now explicitly exposed in frame initial Indeterminant will be automatically loaded when needed from /var/aw/var/LatexWiki/INDET.NRLIB/INDET w:Union(Integer,Indeterminant)
q:=(w^2-1)/(w-1)This is the reasonable result most users can expect.
w is declared as being in Union(Integer,Indeterminant) but has not been given a value.