meaning of %

13 views
Skip to first unread message

Ralf Hemmecke

unread,
May 6, 2024, 1:33:16 PM5/6/24
to fricas-devel
Who can guess what the output of (3) will be just from Section 1.3.2 of
the Book?

%%% (1) -> x1 := 1

(1) 1
Type: PositiveInteger
%%% (2) -> x2 := 2*%; x3 := 100+%;

Type: PositiveInteger
%%% (3) -> [x1,x2,x3]


Spoiler. FriCAS seems to have the same semantics as Mathematica (which
is different from Maple).

Ralf

PS: I know, Qian can.

Waldek Hebisch

unread,
May 6, 2024, 2:29:30 PM5/6/24
to fricas...@googlegroups.com
On Mon, May 06, 2024 at 07:33:13PM +0200, Ralf Hemmecke wrote:
> Who can guess what the output of (3) will be just from Section 1.3.2 of the
> Book?
>
> %%% (1) -> x1 := 1
>
> (1) 1
> Type: PositiveInteger
> %%% (2) -> x2 := 2*%; x3 := 100+%;
>
> Type: PositiveInteger
> %%% (3) -> [x1,x2,x3]
>

Hmm, for me FriCAS produces expected result. And while I now
have "insider knowledge" my expectations concerning previous
result did not chage compared to my first contact with Axiom.
What did you expect?

--
Waldek Hebisch

Ralf Hemmecke

unread,
May 6, 2024, 3:24:46 PM5/6/24
to fricas...@googlegroups.com
The question is whether % refers to the value of the last line (A) or to
the value of the last evaluated expression (B).
Mathematica and Axiom use semantics (A), Maple uses (B).

I expected (B), i.e. x3=102.

I just say, such example should be added to the book.

Ralf

Waldek Hebisch

unread,
May 6, 2024, 3:44:18 PM5/6/24
to fricas...@googlegroups.com
Well, 'x2 := 2*%; x3 := 100+%;' is a single expression, so really
no difference in this case if you say "expression" or "line". In
fact, in files you may have multiline expressions, so saying
"expression" is more precise.

> I just say, such example should be added to the book.

I would prefer:

x1 := 1
x2 := 2*%; x3 := 100 + %

with explantation that the second line is a compound expression.

Maybe also

for i in 1..2 repeat x2 := i*x2

as example of Void result.

--
Waldek Hebisch

Ralf Hemmecke

unread,
May 6, 2024, 4:12:06 PM5/6/24
to fricas...@googlegroups.com
>> The question is whether % refers to the value of the last line (A) or to the
>> value of the last evaluated expression (B).
>> Mathematica and Axiom use semantics (A), Maple uses (B).
>>
>> I expected (B), i.e. x3=102.
>
> Well, 'x2 := 2*%; x3 := 100+%;' is a single expression, so really
> no difference in this case if you say "expression" or "line". In
> fact, in files you may have multiline expressions, so saying
> "expression" is more precise.

Well, I know that there are compound expressions, but up to now an
expression for me ended at ";".

In fact, what you describe is

(x2 := 2*%; x3 := 100+%)

with the parentheses to make it into a compound expression.
But even with parens I wouldn't have a clue what % refers to if it is
not precisely specified. It is not necessarily clear, that the second %
refers to the same value as the first %, except if one claims that a
compound statement basically behaves like a function with % as a parameter.

Looks like this is exactly what FriCAS does.

%%% (10) -> x1 := 1

(10) 1
Type: PositiveInteger
%%% (11) -> for i in 1..2 repeat (x2:=x1+%;x3:=5*%)
Type: Void
%%% (12) -> [x1,x2,x3]

(12) [1, 2, 5]

Maple gives something else.

> x1:=1;
x1 := 1

> for i from 1 to 2 do x2:=x1+%; x3:=5*%; end do;
x2 := 2

x3 := 10

x2 := 11

x3 := 55

> [x1,x2,x3];
[1, 11, 55]


>> I just say, such example should be added to the book.
>
> I would prefer:
>
> x1 := 1
> x2 := 2*%; x3 := 100 + %
>
> with explantation that the second line is a compound expression.

So basically when pressing enter, then the whole thing that FriCAS
receives is counted as one (maybe compound) expression and this whole
thing is evaluated and its value is that of the last subexpression (in
case it is compound).
And % refers to the last evaluation, i.e. the value that was computed
when the user pressed ENTER previously (with a non-trivial input).

> Maybe also
>
> for i in 1..2 repeat x2 := i*x2
>
> as example of Void result.

Good as an example, but I think that loops create Void values is
described already somewhere.

Ralf
Reply all
Reply to author
Forward
0 new messages