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

1 2 3
Editor: Mark Clements
Time: 2009/07/12 00:17:10 GMT-7
Note: Fixed links to new wiki

changed:
-- http://wiki.axiom-developer.org/TuplesProductsAndRecords
-
-- http://wiki.axiom-developer.org/SandBoxDirectProduct
-
-- http://wiki.axiom-developer.org/187TroubleWithTuples
-
-- http://wiki.axiom-developer.org/CartesianProduct
- http://axiom-wiki.newsynthesis.org/TuplesProductsAndRecords

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

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

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

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 G690 Use HyperDoc Browse or issue )what op G690 to learn if there is any operation containing " G690 " 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