On 02/05/2018 05:20 PM, [email protected] wrote:
> If I understand correctly, the "variables" on the LHS of assignments
> are Aldor (whatever) variables that are bound (refer to) to more
> complicated Aldor objects with type in some domain, like
> Variable(b).
Yes. And since you refer to Aldor. Actually, I don't see anything
specifically "symbolic" in Aldor. It's just an ordinary programming
language like C, C++, Python, only that Aldor (like SPAD) uses static
types. And use of these static types (the type of an object is know at
compile time) is something that is not so common in CAS design. And most
newer developments in CAS with types are influenced by SCRATCHPAD II/AXIOM.
But note that FriCAS has actually two languages.
1) the compiler language (which is pretty similar to Aldor) and can
be used in .spad files,
2) the (interpreter) language that can be used in a FriCAS session
or in .input files.
The both agree to quite a big extend, but there is quite a difference
when it comes to types. Interpreter allows to be quite vague with types.
It allows input that would lead to compile time errors in .spad files.
The interpreter basically "helps" the user by throwing in an appropriate
type. That is, of course, guessing. The interpreter might make a wrong
guess, then the user is often confused, but one can usually help the
interpreter by adding explicit type information.
I don't have something better that comes to my mind, so here a stupid
example.
(2) -> gcd(4,6)
(2) 2
Type: PositiveInteger
(3) -> gcd(4,6)@Fraction(Integer)
(3) 1
Type: Fraction(Integer)
> Let me write down another example to test if I've understood (could
> you tell me if I'm wrong?)
> a:=a
> -- "a" on the LHS is an Aldor variable (a reference to an object) ,
> "a" on the RHS is an object of type Variable(a) coercible to Symbol.
Right. These are two different a.
> a:=1
> -- "a" on the LHS is the same Aldor variable as above. "a" now
> reference to "1:Integer" and the value a:Variable(a) -- no mor linked
> -- disappears from the scope.
Well. Not quite. You are right if you mean the behaviour in a FriCAS
session. For Aldor it would be a bit more difficult to do that.
First of all, Aldor would accept
a := a
===================
#include "aldor"
#include "aldorio"
main(): () == {
local a: Integer;
a := a;
}
===================
but that wouldn't give the a on the lhs any value. No, it's not a symbol
that one assigns there, because that would be a type violation. The type
of a is Integer and Symbol wouldn't match.
Second, if you have
a: Integer := 1
a: String := "hello"
then Aldor would reject this at compile time
$ aldor foo.as
"foo.as", line 9: a: String := "Hello World";
........^
[L9 C9] #1 (Error) Variables cannot have different types in the same scope.
(see Note 1)
"foo.as", line 10: a: Integer := 1;
........^
[L10 C9] #2 (Note 1) (cf. L9 C9)
I haven't checked, but it's probably the same for SPAD.
In the interpreter (a FriCAS session) a (programming) variable can only
have one type. So usually you see things like this.
(1) -> a: Integer := 1
(1) 1
Type: Integer
(2) -> a: String := "hello"
You cannot declare a to be of type String because either the
declared type of a or the type of the value of a is different
from String .
In your case you were lucky, because you haven't given an explicit type
for a and thus the interpreter feels free to assign a new type to a.
> f(x) == x+a -- who is "a" on RHS?
If we were in Aldor, that lives under the name of "free variable". That
is, it't the a that is in the scope around this definition. If there is
no such a then bad luck.
The interpreter, would probably interpret you a as a symbol. For x you
also haven't given type information, so it's of unknown type. So the
interpretation of the whole thing has to wait until you call that
function and provide a specific x of a specific type.
Then look what happens.
(6) -> f(x)==x+a
Compiled code for f has been cleared.
1 old definition(s) deleted for function or rule f
Type: Void
(7) -> f(a)
Compiling function f with type Variable(a) -> Polynomial(Integer)
(7) 2 a
Type: Polynomial(Integer)
Oh suddenly the a is considered as a variable of a polynomial ring.
(8) -> f(x)
Compiling function f with type Variable(x) -> Polynomial(Integer)
(8) x + a
Type: Polynomial(Integer)
Also this leads to a polynomial. But look at the input type. Now you
have two functions.
And now a third and fourth function.
(9) -> f 3
Compiling function f with type PositiveInteger -> Polynomial(Integer
)
(9) a + 3
Type: Polynomial(Integer)
(10) -> f(sin x)
Compiling function f with type Expression(Integer) -> Expression(
Integer)
(10) sin(x) + a
Type: Expression(Integer)
All those functions have different source and target types.
So with "f(x)==x+a" you have defined more like a pattern that interprets
to a function definition at the time you first call this function.
> f(z)
> --- => z+1 so "a" above was an Aldor variable
As I just demonstrated above without the assignment "a:=1" it's
interpreted as the symbol (or Variable(a)).
Look what happens, when I do this.
(11) -> a := 1
Compiled code for f has been cleared.
(11) 1
Type: PositiveInteger
As a side effect of this assignment, (compiled) definitions for f are
removed.
(12) -> f(3)
Compiling function f with type PositiveInteger -> PositiveInteger
(12) 4
Type: PositiveInteger
> If my understanding is correct, the situation is pretty much like
> Sympy
I would say, yes. SageMath is another example.
> I understand. (Actually it seems that also mathemagix [2] does it :)
> but I'm not a mathemagix user. )
Oh yes. I cannot deny it. And there are good reasons to have several
representations.
Oh, before I forget, I see the strong points of FriCAS more in the power
of building type hierarchies.
Look through the examples at http://fricas.github.io/
http://axiom-wiki.newsynthesis.org/SandBoxNonCommutativeLaurentPolynomials
http://axiom-wiki.newsynthesis.org/FunWithFunctions
Ralf
PS:
In fact, one can have polynomials in several variables that have
matrices as their ring of coefficients.
(1) -> Z==>Integer; Q==>Fraction Z; S==>SquareMatrix(2, Q)
Type: Void
(2) -> P ==> HDMP(['x,'y],S)
Type: Void
(4) -> q1 := 2/3; q2 := 5/7;
Type: Fraction(Integer)
(5) -> s: S := matrix [[q1,q2],[1,0]]
+2 5+
|- -|
(5) |3 7|
| |
+1 0+
Type: SquareMatrix(2,Fraction(Integer))
(7) -> sy := inverse s
+0 1 +
| |
(7) |7 14|
|- - --|
+5 15+
Type: Union(SquareMatrix(2,Fraction(Integer)),...)
(12) -> p: P := s + sy*y
+0 1 + +2 5+
| | |- -|
(12) |7 14|y + |3 7|
|- - --| | |
+5 15+ +1 0+
Type:
HomogeneousDistributedMultivariatePolynomial([x,y],SquareMatrix(2,Fraction(Integer)))
(13) -> p^2
+ 7 14+ +73 10+
| - - --| |-- --|
| 5 15| 2 +2 0+ |63 21|
(13) | |y + | |y + | |
| 98 511 | +0 2+ |2 5 |
|- -- --- | |- - |
+ 75 225 + +3 7 +
Type:
HomogeneousDistributedMultivariatePolynomial([x,y],SquareMatrix(2,Fraction(Integer)))
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.