[PATCH] slightly improve tantrick

5 views
Skip to first unread message

Qian Yun

unread,
Oct 19, 2023, 10:12:07 AM10/19/23
to fricas-devel
It actually makes no sense to test the sign of a and b before
they divide. Because they can be of form such as "1/aa".
Since the purpose of 'tantrick' is to minimize zeros in
the denominator of "a/b" or "b/a", so it makes perfect sense
to do the division first, then check for signs.

I have compared results in src/input/ (by printing out the
infinite integrals), very few changes, but they are all
improvements, not regressions.

--- a/src/algebra/irexpand.spad
+++ b/src/algebra/irexpand.spad
@@ -102,6 +103,9 @@
-- returns 2 atan(a/b) or 2 atan(-b/a) whichever looks better
-- they differ by a constant so it's ok to do it from an IR
tantrick(a, b) ==
+ c := a/b
+ a := numerator c
+ b := denominator c
retractIfCan(a)@Union(Q, "failed") case Q => 2 * atan(-b/a)
sb := sign b
if sb case Z then return 2 * atan(a/b)


See the following examples, the first one avoids a discontinuity at x=0;
the second one turns atan(1/largeExpression) into -atan(largeExpression)
which takes less printing space and potentially avoids discontinuity.

- Qian

integrate(1/(sqrt(10) - x^2)^(1/2), x) -- from integ.input

==== before
+----------+
| +--+ 2
\|\|10 - x
(1) - atan(-------------)
x
==== after
x
(1) atan(-------------)
+----------+
| +--+ 2
\|\|10 - x


in1854a:=integrate(1/(z-1)/(1/(z-I))^(1/2), z) -- from mapleok.input

==== before [part of result]
+-----+
| 1 +-----+ 1
- 2 |----- \|I - 1 atan(----------------) + 2
\|z - I +-----+
| 1 +-----+
|----- \|I - 1
\|z - I
----------------------------------------------]
+-----+
| 1
|-----
\|z - I
==== after [part of result]
+-----+ +-----+
| 1 +-----+ | 1 +-----+
2 |----- \|I - 1 atan( |----- \|I - 1 ) + 2
\|z - I \|z - I
--------------------------------------------]
+-----+
| 1
|-----
\|z - I

Waldek Hebisch

unread,
Oct 19, 2023, 5:40:11 PM10/19/23
to fricas...@googlegroups.com
On Thu, Oct 19, 2023 at 10:12:02PM +0800, Qian Yun wrote:
> It actually makes no sense to test the sign of a and b before
> they divide. Because they can be of form such as "1/aa".
> Since the purpose of 'tantrick' is to minimize zeros in
> the denominator of "a/b" or "b/a", so it makes perfect sense
> to do the division first, then check for signs.
>
> I have compared results in src/input/ (by printing out the
> infinite integrals), very few changes, but they are all
> improvements, not regressions.

Looks OK. However, I wonder why you do not do this in 'ilog'?

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