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

Edit detail for #276 the result looks like a record but isn't a record revision 1 of 3

1 2 3
Editor:
Time: 2007/11/17 22:19:51 GMT-8
Note: showTypeInOutput

changed:
-
I make a list :
\begin{axiom}
L := map (t +-> [t, divide (10*t,21)], expand (1..21-1))
\end{axiom}

I can't extract the second term :

\begin{axiom}
select (t +-> t.1=2, L)                           -- empty
\end{axiom}

I get an error :
\begin{axiom}
select (t +-> (t.2).remainder = 1, L)             -- erreur
\end{axiom}

It seems right :
\begin{axiom}
Lc := reduce (append, L)
c := Lc.4
\end{axiom}

But I can't get the quotient :
\begin{axiom}
c.quotient   
\end{axiom}
                                 
divide is right :
\begin{axiom} 
c2 := divide (20, 21)
c2.quotient
\end{axiom}

And all theses commands are right :
\begin{axiom}
Lb := map (t +-> [t, (10*t) rem 21, (10*t) quo 21], expand (1..21-1))
select (t +-> t.1=2, Lb)
select (t +-> t.2 = 1, Lb)
reduce (append, Lb)
\end{axiom}

From RalfHemmecke Mon Mar 20 07:45:08 -0600 2006
From: Ralf Hemmecke
Date: Mon, 20 Mar 2006 07:45:08 -0600
Subject: Any?
Message-ID: <20060320074508-0600@wiki.axiom-developer.org>

I don't know why but the result of 
\begin{axiom}
L := map (t +-> [t, divide (10*t,21)], expand (1..21-1))
\end{axiom}
is List List Any. So the interpreter seems to be smart to convert this back
\begin{axiom}
K := first rest first L
\end{axiom}
to Record(quotient: Integer,remainder: Integer). But it only looks like that.
\begin{axiom}
K.remainder
\end{axiom}
gives an error. WHY?

A workaround is the following:
\begin{axiom}
R := Record(quotient: Integer,remainder: Integer)
H := K :: R
H.remainder
\end{axiom}

Ralf

From greg Mon Mar 20 09:54:30 -0600 2006
From: greg
Date: Mon, 20 Mar 2006 09:54:30 -0600
Subject: Yes, the internal type is Any
Message-ID: <20060320095430-0600@wiki.axiom-developer.org>

The internal types of these objects are of type Any but the interpreter uses the original types when it prints theses objects. See any.spad.pamphlet for information.
\begin{axiom}
L := map (t +-> [t, divide (10*t,21)], expand (1..5))
Lc := reduce (append, L)
c := Lc.4
c
)display type c
domainOf(c)

\end{axiom}



From greg Mon Mar 20 10:01:12 -0600 2006
From: greg
Date: Mon, 20 Mar 2006 10:01:12 -0600
Subject: property change
Message-ID: <20060320100112-0600@wiki.axiom-developer.org>

Status: open => closed 


From BillPage Mon Mar 20 10:11:46 -0600 2006
From: Bill Page
Date: Mon, 20 Mar 2006 10:11:46 -0600
Subject: Re: Any?
Message-ID: <20060320101146-0600@wiki.axiom-developer.org>

To extract second term use:
\begin{axiom}
select(x+->x.1::Integer=2, L)
\end{axiom}

But I think the 2nd problem requiring the coercion to Record of
something that is already apparently of that type is a bug.

From greg Mon Mar 20 10:46:06 -0600 2006
From: greg
Date: Mon, 20 Mar 2006 10:46:06 -0600
Subject: Here it's possible to use a Record
Message-ID: <20060320104606-0600@wiki.axiom-developer.org>

\begin{axiom}
L := map (t +-> makeRecord(t, divide (10*t,21)), expand (1..21-1))
select (t +-> t.part1=2, L)
select (t +-> (t.part2).remainder = 1, L)
L.2.part2.quotient
\end{axiom}

From greg Mon Mar 20 19:40:15 -0600 2006
From: greg
Date: Mon, 20 Mar 2006 19:40:15 -0600
Subject: bug report reopened
Message-ID: <20060320194015-0600@wiki.axiom-developer.org>

After reflexion I think I can't take the decision to close this bug report. First, some persons can prefer to have the real type displayed instead of the original one. Second, Bill Page thinks that the 2nd problem requiring the coercion to Record is a bug and third it's not possible to extract element of an object of type Any with Record as its original type but it's possible if the original type is List or Vector for example.
\begin{axiom}
a:= [[x,2],4,divide(10,7)]
b:=a.1
)di type b
b.1
c:=a.3
)di type c
c.quotient
\end{axiom}

From greg Mon Mar 20 19:40:57 -0600 2006
From: greg
Date: Mon, 20 Mar 2006 19:40:57 -0600
Subject: property change
Message-ID: <20060320194057-0600@wiki.axiom-developer.org>

Status: closed => open 


From BillPage Tue Mar 21 02:09:11 -0600 2006
From: Bill Page
Date: Tue, 21 Mar 2006 02:09:11 -0600
Subject: )set message any off
Message-ID: <20060321020911-0600@wiki.axiom-developer.org>

This command disables the display of the underlying type
of an object of type 'Any'.
\begin{axiom}
)set message any
\end{axiom}

With this option 'off' Axiom displays the 'Type:' in the same
way as ')di type'. This might be useful in order to avoid
confusion in some cases.



From RalfHemmecke Tue Mar 21 03:57:04 -0600 2006
From: Ralf Hemmecke
Date: Tue, 21 Mar 2006 03:57:04 -0600
Subject: 
Message-ID: <20060321035704-0600@wiki.axiom-developer.org>

Well, actually, this is one of the problem why people might find it hard to work with Axiom. 
Of course, Axiom returns for $L$ the best it could. If I write
\begin{axiom}
ans := [2, divide(10*2,21)]
\end{axiom}
then it is clear that the type over which the list is formed have to be made equal.
So we get 'List Any'.
But maybe, it would have been wiser if Axiom had warned about such a construction or Axiom should rather
interpret the outer brackets in
\begin{axiom}
[1, [2,3]]
\end{axiom}
as 'makeRecord'.
\begin{axiom}
makeRecord(1, [2,3])
\end{axiom}

Anyway, the question is also why someone wants to have
\begin{axiom}
L := map (t +-> [t, divide (10*t,21)], expand (1..21-1));
\end{axiom}
in the first place. Wouldn't be 
\begin{axiom}
LL := map (t +-> divide (10*t,21), expand (1..21-1))
\end{axiom}
be sufficient? The argument $t$ is implicitly given through the list structure.
And why not even just compute the following?
\begin{axiom}
L3 := map (t +-> divide (10*t,21).remainder, expand (1..21-1))
\end{axiom}

And as for ')set message any off' is good (no confusion) and bad (no hint what one could do with the expression). 


From unknown Tue Mar 21 04:46:44 -0600 2006
From: unknown
Date: Tue, 21 Mar 2006 04:46:44 -0600
Subject: 
Message-ID: <20060321044644-0600@wiki.axiom-developer.org>

Of corse I can do 
\begin{axiom}
position (t +-> t.remainder=1, map (t +-> divide (10*t, 21), expand  (1..20)))
\end{axiom}

But (I believe) it's nearer the mathematical way to write 

select (t +-> t.2.remainder=1, map (t +-> \[t,divide (10*t, 21)\], expand  (1..20)))

So I find all the solutions, and I remain the initial value which is right.
It's as $F = \{ t \in E \mid P(t) [is\ right]\}$. Hier P(t)=t.2.remainder=1

Axiom believes that List are (almost) only in $E^n$, 

With other CAS I use list as cartesian product of sets. It's very usefull and pretty to read.
  
With axiom I must use Record. 
If I use List I must explain that type I read (Record...) isn't type I have (Any...). It's to complex !

With record the length is fixed, and use of Record... is less pretty than use of List... 

So I prefer that axiom-interpreter translates without question Any type to his own type.
Even if there are difficults aroud this map : The first t is a Polynomial or an Integer ?

\begin{axiom}
map (t +-> [t, X^t-1], expand (0..10))
\end{axiom}
FMy

From RalfHemmecke Tue Mar 21 05:42:11 -0600 2006
From: Ralf Hemmecke
Date: Tue, 21 Mar 2006 05:42:11 -0600
Subject: 
Message-ID: <20060321054211-0600@wiki.axiom-developer.org>

Don't you think that in 
$F = \{ t \in E \mid P(t)\}$
it depends on what your E is?

If you think that E is the set $\{1,2,\ldots, 20\}$ then
something like
\begin{axiom}
)clear all
[t for e in 1..20 | (t:=divide(10*e,21); one?(t.remainder))]
\end{axiom}
looks quite mathematical, n'est pas? Well, there is a local assignment to $t$, but it's short enough.

If you like your way more than perhaps write
\begin{axiom}
K := [divide(10*t,21) for t in 1..20];
[t for t in K | t.remainder=1]
\end{axiom}

And, by the way, if it weren't for the fact that divide in Aldor's libalgebra library has signature::

  divide: (%, %) -> (%, %);

instead of Axiom's::

  divide: (%,%) -> Record(quotient:%,remainder:%)

The above construction would also work in Aldor. 
(The use of 'select' is not possible since it is a reserved keyword in Aldor.)

Ralf

From BillPage Tue Mar 21 06:04:51 -0600 2006
From: Bill Page
Date: Tue, 21 Mar 2006 06:04:51 -0600
Subject: providing specific types vs. duck-typing
Message-ID: <20060321060451-0600@wiki.axiom-developer.org>

FMy,

I think you meant to write:
\begin{axiom}
select(t+->t.remainder=1,map (t +-> divide (10*t, 21), expand  (1..20)))
\end{axiom}
There is no meaning for 't.2'

I disagree that one should use a list as cartesian product of
sets. This is very much against the strong-type design of Axiom.
Instead Axom should provide a type equivalent to the cartesian
product and it should be (nearly) as flexible as Lists. The next
best thing that Axiom has is Record.

When creating an anonymous function you can provide specific types:
\begin{axiom}
L:=map ((t:INT):Record(t:INT,p:POLY INT) +-> [t, X^t-1], expand (0..10))
\end{axiom}
so that the result is clear.

The discussion of Lists, Tuples, Products and Records in Axiom
is an old one. See: 

- http://wiki.axiom-developer.org/TuplesProductsAndRecords

- http://wiki.axiom-developer.org/SandBoxDirectProduct

- http://wiki.axiom-developer.org/187TroubleWithTuples

- http://wiki.axiom-developer.org/CartesianProduct

I agree that Axiom does not get this right. In Aldor the
'Product' type is generalized to 'Cross'.

I do not know yet how to understand the domain 'Any' but
I think it is very interesting. It is probably very close
to what is called "duck typing" in modern terms:

http://en.wikipedia.org/wiki/Duck_typing

This a form of dynamic typing where the values from the
domain 'Any' carry with them their actual types. To me
this seems like a "partially successful" early experiment
with this idea - *Another remarkable first for the Axiom
developers!* But it is only partially sucessful because
all of the implications about how it should interact with
the rest of the static strongly-typed language of Axiom is
not fully worked out.


From BillPage Thu Apr 5 11:11:55 -0500 2007
From: Bill Page
Date: Thu, 05 Apr 2007 11:11:55 -0500
Subject: showTypeInOutput
Message-ID: <20070405111155-0500@wiki.axiom-developer.org>

The switch 'showTypeInOutput' can be used to show the underlying type
of an object of type Any.
\begin{axiom}
)set message any off
showTypeInOutput true
\end{axiom}

Test
\begin{axiom}
a:Any:=[1,"a"]
a.1
(a.1)::Integer
(a.2)::String
\end{axiom}

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

I make a list :

axiom
L := map (t +-> [t, divide (10*t,21)], expand (1..21-1))
LatexWiki Image(1)
Type: List List Any

I can't extract the second term :

axiom
select (t +-> t.1=2, L)
empty
LatexWiki Image(2)
Type: List List Any

I get an error :

axiom
select (t +-> (t.2).remainder = 1, L)             -- erreur
There are 1 exposed and 1 unexposed library operations named elt having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op elt 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. There are no library operations named G1510 Use HyperDoc Browse or issue )what op G1510 to learn if there is any operation containing " G1510 " in its name. There are 1 exposed and 1 unexposed library operations named elt having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op elt 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. There are 4 exposed and 1 unexposed library operations named select having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op select 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 select with argument type(s) AnonymousFunction List List Any
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

It seems right :

axiom
Lc := reduce (append, L)
LatexWiki Image(3)
Type: List Any
axiom
c := Lc.4
LatexWiki Image(4)
Type: Record(quotient: Integer,remainder: Integer)

But I can't get the quotient :

axiom
c.quotient
There are no library operations named c Use HyperDoc Browse or issue )what op c to learn if there is any operation containing " c " in its name.
Cannot find a definition or applicable library operation named c with argument type(s) Variable quotient
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

divide is right :

axiom
c2 := divide (20, 21)
LatexWiki Image(5)
Type: Record(quotient: Integer,remainder: Integer)
axiom
c2.quotient
LatexWiki Image(6)
Type: NonNegativeInteger?

And all theses commands are right :

axiom
Lb := map (t +-> [t, (10*t) rem 21, (10*t) quo 21], expand (1..21-1))
LatexWiki Image(7)
Type: List List Integer
axiom
select (t +-> t.1=2, Lb)
LatexWiki Image(8)
Type: List List Integer
axiom
select (t +-> t.2 = 1, Lb)
LatexWiki Image(9)
Type: List List Integer
axiom
reduce (append, Lb)
LatexWiki Image(10)
Type: List Integer

I don't know why but the result of
axiom
L := map (t +-> [t, divide (10*t,21)], expand (1..21-1))
LatexWiki Image(11)
Type: List List Any

is List List Any. So the interpreter seems to be smart to convert this back

axiom
K := first rest first L
LatexWiki Image(12)
Type: Record(quotient: Integer,remainder: Integer)

to Record(quotient: Integer,remainder: Integer). But it only looks like that.

axiom
K.remainder
There are no library operations named K Use HyperDoc Browse or issue )what op K to learn if there is any operation containing " K " in its name.
Cannot find a definition or applicable library operation named K with argument type(s) Variable remainder
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

gives an error. WHY?

A workaround is the following:

axiom
R := Record(quotient: Integer,remainder: Integer)
LatexWiki Image(13)
Type: Domain
axiom
H := K :: R
LatexWiki Image(14)
Type: Record(quotient: Integer,remainder: Integer)
axiom
H.remainder
LatexWiki Image(15)
Type: PositiveInteger?

Ralf

Yes, the internal type is Any --greg, Mon, 20 Mar 2006 09:54:30 -0600 reply
The internal types of these objects are of type Any but the interpreter uses the original types when it prints theses objects. See any.spad.pamphlet for information.
axiom
L := map (t +-> [t, divide (10*t,21)], expand (1..5))
LatexWiki Image(16)
Type: List List Any
axiom
Lc := reduce (append, L)
LatexWiki Image(17)
Type: List Any
axiom
c := Lc.4
LatexWiki Image(18)
Type: Record(quotient: Integer,remainder: Integer)
axiom
c
LatexWiki Image(19)
Type: Record(quotient: Integer,remainder: Integer)
axiom
)display type c
Type of value of c: Any domainOf(c)
LatexWiki Image(20)
Type: OutputForm?

property change --greg, Mon, 20 Mar 2006 10:01:12 -0600 reply
Status: open => closed

To extract second term use:
axiom
select(x+->x.1::Integer=2, L)
LatexWiki Image(21)
Type: List List Any

But I think the 2nd problem requiring the coercion to Record of something that is already apparently of that type is a bug.

Here it's possible to use a Record --greg, Mon, 20 Mar 2006 10:46:06 -0600 reply
axiom
L := map (t +-> makeRecord(t, divide (10*t,21)), expand (1..21-1))
LatexWiki Image(22)
Type: List Record(part1: Integer,part2: Record(quotient: Integer,remainder: Integer))
axiom
select (t +-> t.part1=2, L)
LatexWiki Image(23)
Type: List Record(part1: Integer,part2: Record(quotient: Integer,remainder: Integer))
axiom
select (t +-> (t.part2).remainder = 1, L)
LatexWiki Image(24)
Type: List Record(part1: Integer,part2: Record(quotient: Integer,remainder: Integer))
axiom
L.2.part2.quotient
LatexWiki Image(25)
Type: NonNegativeInteger?

bug report reopened --greg, Mon, 20 Mar 2006 19:40:15 -0600 reply
After reflexion I think I can't take the decision to close this bug report. First, some persons can prefer to have the real type displayed instead of the original one. Second, Bill Page thinks that the 2nd problem requiring the coercion to Record is a bug and third it's not possible to extract element of an object of type Any with Record as its original type but it's possible if the original type is List or Vector for example.
axiom
a:= [[x,2],4,divide(10,7)]
LatexWiki Image(26)
Type: List Any
axiom
b:=a.1
LatexWiki Image(27)
Type: List Polynomial Integer
axiom
)di type b
Type of value of b: Any b.1
LatexWiki Image(28)
Type: Polynomial Integer
axiom
c:=a.3
LatexWiki Image(29)
Type: Record(quotient: Integer,remainder: Integer)
axiom
)di type c
Type of value of c: Any c.quotient
There are no library operations named c Use HyperDoc Browse or issue )what op c to learn if there is any operation containing " c " in its name.
Cannot find a definition or applicable library operation named c with argument type(s) Variable quotient
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

property change --greg, Mon, 20 Mar 2006 19:40:57 -0600 reply
Status: closed => open

)set message any off --Bill Page, Tue, 21 Mar 2006 02:09:11 -0600 reply
This command disables the display of the underlying type of an object of type Any.
axiom
)set message any
----------------------------- The any Option ------------------------------
Description: print the internal type of objects of domain Any
The any option may be followed by any one of the following:
-> on off
The current setting is indicated within the list.

With this option off Axiom displays the Type: in the same way as )di type. This might be useful in order to avoid confusion in some cases.

Well, actually, this is one of the problem why people might find it hard to work with Axiom. Of course, Axiom returns for LatexWiki Image the best it could. If I write
axiom
ans := [2, divide(10*2,21)]
LatexWiki Image(30)
Type: List Any

then it is clear that the type over which the list is formed have to be made equal. So we get List Any. But maybe, it would have been wiser if Axiom had warned about such a construction or Axiom should rather interpret the outer brackets in

axiom
[1, [2,3]]
LatexWiki Image(31)
Type: List Any

as makeRecord.

axiom
makeRecord(1, [2,3])
LatexWiki Image(32)
Type: Record(part1: PositiveInteger?,part2: List PositiveInteger?)

Anyway, the question is also why someone wants to have

axiom
L := map (t +-> [t, divide (10*t,21)], expand (1..21-1));
Type: List List Any

in the first place. Wouldn't be

axiom
LL := map (t +-> divide (10*t,21), expand (1..21-1))
LatexWiki Image(33)
Type: List Record(quotient: Integer,remainder: Integer)

be sufficient? The argument LatexWiki Image is implicitly given through the list structure. And why not even just compute the following?

axiom
L3 := map (t +-> divide (10*t,21).remainder, expand (1..21-1))
LatexWiki Image(34)
Type: List Integer

And as for )set message any off is good (no confusion) and bad (no hint what one could do with the expression).

Of corse I can do
axiom
position (t +-> t.remainder=1, map (t +-> divide (10*t, 21), expand  (1..20)))
LatexWiki Image(35)
Type: PositiveInteger?

But (I believe) it's nearer the mathematical way to write

select (t +-> t.2.remainder=1, map (t +-> LatexWiki Image, expand (1..20)))

So I find all the solutions, and I remain the initial value which is right. It's as LatexWiki Image. Hier P(t)=t.2.remainder=1

Axiom believes that List are (almost) only in LatexWiki Image,

With other CAS I use list as cartesian product of sets. It's very usefull and pretty to read.

With axiom I must use Record. If I use List I must explain that type I read (Record...) isn't type I have (Any...). It's to complex !

With record the length is fixed, and use of Record... is less pretty than use of List...

So I prefer that axiom-interpreter translates without question Any type to his own type. Even if there are difficults aroud this map : The first t is a Polynomial or an Integer ?

axiom
map (t +-> [t, X^t-1], expand (0..10))
LatexWiki Image(36)
Type: List List Fraction Polynomial Integer

FMy?

Don't you think that in LatexWiki Image it depends on what your E is?

If you think that E is the set LatexWiki Image then something like

axiom
)clear all
All user variables and function definitions have been cleared. [t for e in 1..20 | (t:=divide(10*e,21); one?(t.remainder))]
LatexWiki Image(37)
Type: List Record(quotient: Integer,remainder: Integer)

looks quite mathematical, n'est pas? Well, there is a local assignment to LatexWiki Image, but it's short enough.

If you like your way more than perhaps write

axiom
K := [divide(10*t,21) for t in 1..20];
Type: List Record(quotient: Integer,remainder: Integer)
axiom
[t for t in K | t.remainder=1]
LatexWiki Image(38)
Type: List Record(quotient: Integer,remainder: Integer)

And, by the way, if it weren't for the fact that divide in Aldor's libalgebra library has signature:

  divide: (%, %) -> (%, %);

instead of Axiom's:

  divide: (%,%) -> Record(quotient:%,remainder:%)

The above construction would also work in Aldor. (The use of select is not possible since it is a reserved keyword in Aldor.)

Ralf

providing specific types vs. duck-typing --Bill Page, Tue, 21 Mar 2006 06:04:51 -0600 reply
FMy?,

I think you meant to write:

axiom
select(t+->t.remainder=1,map (t +-> divide (10*t, 21), expand  (1..20)))
LatexWiki Image(39)
Type: List Record(quotient: Integer,remainder: Integer)

There is no meaning for t.2

I disagree that one should use a list as cartesian product of sets. This is very much against the strong-type design of Axiom. Instead Axom should provide a type equivalent to the cartesian product and it should be (nearly) as flexible as Lists. The next best thing that Axiom has is Record.

When creating an anonymous function you can provide specific types:

axiom
L:=map ((t:INT):Record(t:INT,p:POLY INT) +-> [t, X^t-1], expand (0..10))
LatexWiki Image(40)
Type: List Record(t: Integer,p: Polynomial Integer)

so that the result is clear.

The discussion of Lists, Tuples, Products and Records in Axiom is an old one. See:

I agree that Axiom does not get this right. In Aldor the Product type is generalized to Cross.

I do not know yet how to understand the domain Any but I think it is very interesting. It is probably very close to what is called "duck typing" in modern terms:

http://en.wikipedia.org/wiki/Duck_typing

This a form of dynamic typing where the values from the domain Any carry with them their actual types. To me this seems like a "partially successful" early experiment with this idea - Another remarkable first for the Axiom developers! But it is only partially sucessful because all of the implications about how it should interact with the rest of the static strongly-typed language of Axiom is not fully worked out.

showTypeInOutput --Bill Page, Thu, 05 Apr 2007 11:11:55 -0500 reply
The switch showTypeInOutput can be used to show the underlying type of an object of type Any.
axiom
)set message any off
showTypeInOutput true
LatexWiki Image(41)
Type: String

Test

axiom
a:Any:=[1,"a"]
LatexWiki Image(42)
Type: Any
axiom
a.1
LatexWiki Image(43)
Type: Any
axiom
(a.1)::Integer
LatexWiki Image(44)
Type: Integer
axiom
(a.2)::String
LatexWiki Image(45)
Type: String