interpreter parses differently than compiler

5 views
Skip to first unread message

Ralf Hemmecke

unread,
Nov 3, 2022, 4:19:02 AM11/3/22
to fricas-devel
I don't know whether this is a bug or not. However, it took me some time
to figure out where the problem was in an .input script.

(6) -> i := 2; j := 2; [if i=j then 1 else 0 for j in 1..5]

(6) [1]
Type: List(PositiveInteger)
(7) -> i := 2; j := 2; [(if i=j then 1 else 0) for j in 1..5]

(7) [0, 1, 0, 0, 0]
Type: List(NonNegativeInteger)


I am somewhat sure that it is a bug, because of the attached .spad file.
It behaves as expected and gives the output below, but behaves
differently from what the interpreter does.

(17) -> z1 := [[f1(m,n) for n in 1..5] for m in 1..5];

Type:
List(List(List(Integer)))
(18) -> z2 := [[f2(m,n) for n in 1..5] for m in 1..5];

Type:
List(List(List(Integer)))
(19) -> (z1=z2)@Boolean

(19) true
Type:
Boolean
(20) -> z1

(20)
[
[[1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0],
[1, 0, 0, 0, 0]]
,

[[0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 0, 0, 0],
[0, 1, 0, 0, 0]]
,

[[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0],
[0, 0, 1, 0, 0]]
,

[[0, 0, 0, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 1, 0],
[0, 0, 0, 1, 0]]
,

[[0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1],
[0, 0, 0, 0, 1]]
]
Type:
List(List(List(Integer)))
foo.spad

Qian Yun

unread,
Nov 3, 2022, 7:55:09 AM11/3/22
to fricas...@googlegroups.com
(1) -> i := 2; j := 2; [if i=j then 1 else 0 for j in 1..5]

(1) [1]
Type:
List(PositiveInteger)
(2) -> i := 1; j := 2; [if i=j then 1 else 0 for j in 1..5]

(2) [0, 0, 0, 0, 0]
Type:
List(NonNegativeInteger)

So the interpreter treats "[if i=j then 1 else 0 for j in 1..5]"
as "[if i=j then 1 else (0 for j in 1..5)]".

- Qian
Reply all
Reply to author
Forward
0 new messages