simplifyExp, FunctionSpace and RetractableTo Integer

18 views
Skip to first unread message

Qian Yun

unread,
Feb 8, 2024, 11:42:43 PM2/8/24
to fricas-devel
When I was improving "simplifyExp", I met this problem:

(a^b)^n can get simplified into a^(b*n), when n is Integer.

but in package TRMANIP(R,F), where F has FunctionSpace R,
but F does not have RetractableTo Integer.

So for (a^b)^f, there's no way to tell if (simplifyExp f) is
Integer or not.

But in FunctionSpace, there is

isMult : % -> Union(Record(coef:Z, var:K),"failed")

I think this function can be used to effectively test if
a value can be retracted to Integer.

So, my question is, should FunctionSpace export RetractableTo
Integer under some circumstances?

- Qian

Waldek Hebisch

unread,
Feb 9, 2024, 1:09:15 AM2/9/24
to fricas...@googlegroups.com
That is a subtle question. First, what RetractableTo really
mean? IMO RetractableTo should be asserted when there we
have effective test for membership in a subset. OTOH
things like isMult and isTimes work at level of representation.

In principle representaion of FunctionSpace can be highly
noncanonical and isMult may fail even if expression really
is equal to an integer.

So, IMO 'isMult' can not be used to implement general retraction
to integers.

You ask about "some circumstances". Currently FunctionSpace(R)
where R is a Ring has RetractableTo(Polynomial(R)). Polynomial(R)
has FullyRetractableTo(R). Arguably this RetractableTo could
be replaced by FullyRetractableTo, so assuming that R
has RetractableTo(Integer) then also FunctionSpace(R) would
have RetractableTo(Integer). OTOH in TranscendentalManipulations
R is only GcdDomain, so no warrantly that we can retract it
to ingegers.

Concerning 'isMult', export in FunctionSpace is a lie, it
is defined only in two cases:

a) when R is a Ring which has RetractableTo(Integer) (so really
the case above)

b) when the domain is Expression(R) and R is an AbelianMonoid
which is _not_ a Ring

Moreover, when R is a Ring 'isMult' seem to ignore denominator.

There are also different considerations: some changes that would
be desirable from logical/mathematical point of view lead to
problematic function selection. In other words interpreter
selects different functions than desired by average user.
As an example let me mention 'inverse' for matrices. 'inverse'
makes sense over rings and in particular we can compute it
over integers. But we export it only for fields, because
users usualy want inverse over rationals instead of not
so interesting statement that invers over integers does not
exist.

I do not think that is is a problem for retraction to integers, but
just mention the issue for completeness.

--
Waldek Hebisch

Qian Yun

unread,
Feb 9, 2024, 9:11:11 AM2/9/24
to fricas...@googlegroups.com
OK, so let's leave FunctionSpace alone and focus on my original
problem with simplifyExp:

In COMBF, "ipow" is conditionally defined depends on RetractableTo
Integer.

So is it a good idea to check for RetractableTo Integer conditionally
in "simplifyExp"?

- Qian

Waldek Hebisch

unread,
Feb 9, 2024, 10:18:23 AM2/9/24
to fricas...@googlegroups.com
On Fri, Feb 09, 2024 at 10:11:07PM +0800, Qian Yun wrote:
> OK, so let's leave FunctionSpace alone and focus on my original
> problem with simplifyExp:
>
> In COMBF, "ipow" is conditionally defined depends on RetractableTo
> Integer.
>
> So is it a good idea to check for RetractableTo Integer conditionally
> in "simplifyExp"?

If you need this yes. AFAICS main use of 'simplifyExp' is in
case when we have RetractableTo Integer.

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