Iterators in rule RewriteRules

3 views
Skip to first unread message

Neven Sajko

unread,
Aug 6, 2021, 5:21:46 AM8/6/21
to fricas-devel
Hello,

It seems that iterators are not supported in rewrite rules? This is
not an issue currently for me (because I can use `sum` instead of
`reduce`), but it might be good to bring it to your attention.

I tried to make a Ruleset like this:

sum_rule := rule
sin(X)^Y == sum(sin(n * X), n = 1..Y)
cos(X)^Y == reduce(_+, [cos('n * X) for n in 1..Y])

Note that the first rule, with sum, works fine. But the second rule
causes this error:

The index variable in an iterator must be a symbol and QUOTEn is not one.

Trying to change the n to a Symbol also doesn't work:

Line 1: sum_rule := rule
Line 2: sin(X)^Y == sum(sin(n * X), n = 1..Y)
Line 3: cos(X)^Y == reduce(_+, [cos(n * X) for "n"::Symbol in 1..Y])
..A......................................B...................C
Error A: (from #\A up to #\C) Ignored.
Error B: Improper syntax.
2 error(s) parsing


Regards,
Neven

Waldek Hebisch

unread,
Aug 6, 2021, 8:08:53 AM8/6/21
to fricas...@googlegroups.com
On Fri, Aug 06, 2021 at 09:21:34AM +0000, Neven Sajko wrote:
> Hello,
>
> It seems that iterators are not supported in rewrite rules? This is
> not an issue currently for me (because I can use `sum` instead of
> `reduce`), but it might be good to bring it to your attention.

Iterators are unlikely to be ever supported in rewrite rules.
FriCAS patterns are matching symbolic data (in practice
expressions). Iterators are pure code, with no "computable"
symbolic representation.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages