On Thu, Mar 18, 2021 at 01:12:03PM -0700, Tobias Neumann wrote:
> I am currently trying to see if I can accelerate my code around series
> expansions. I really like that series are lazy in FriCAS, but I wonder
> what impact multiple operations on the series (or the underlying
> stream), like integration etc. have. I would assume that up to memory
> requirements that "save" or delay all the performed operations, there
> should be no
> performance penalty compared to a non-lazy evaluation.
>
> Anyway, while testing I came up with this example, where some expression
> is series expanded in two different ways.
>
> )clear completely
> )set mes tim on
>
> x := taylor(x');
> s1 := x^2 + cos(x) + x^8/ sqrt(x-1);
>
> s2 := taylor(y^2 + cos(y) + y^8/ sqrt(y-1),y=0);
>
> approximate(s1,450);
> approximate(s2,450);
>
> approximate(s1,450);
> approximate(s2,450);
>
>
> When running the code (see below) the first method of evaluation is three
> times faster than the second. (A second evaluation runs in the same time
> for both cases, probably because the results are cached, but that's not
> relevant for me).
>
> In my case I start with an Expression(Integer), so I (obviously) can only
> use the second version from the ExpressionToUnivariatePowerSeries package.
> But my idea is that maybe I can improve the performance if I understand
> why the first method is so much faster.
>
> I would have expected that the ExpressionToUnivariatePowerSeries package
> does something like "subst(expression, x=series('x))", symbolically
> speaking, but then it should be just as fast.
Well, we have:
(1) -> y^2 + cos(y) + y^8/ sqrt(y-1)
2 +-----+ 8
(cos(y) + y )\|y - 1 + y
(1) --------------------------
+-----+
\|y - 1
Type: Expression(Integer)
Replacing in this y by series for x I get comparable time to expanding
expression.
> In principle I see two ways to do the series expansions: Compute the
> expansion as a whole for the whole expression (for example by taking
> derivatives for a Taylor series). Or do it for each function separately,
> and use the Cauchy product to multiply the individual series together, or
> add them, etc. For the first series expansion example this is clearly
> done,
No, FriCAS uses derivatives only as fallback, when it knows no
better method. For elementaty functions, "standard" special
functions and few other things FriCAS has much faster methods.
> but maybe not for ExpressionToUnivariatePowerSeries and this could
> be the difference?
I think it is order of operations that matters. s1 uses good
formula, formula used to compute s2 is subject to automatic
transformatins and this makes it less efficient.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/20210318211722.GA9786%40math.uni.wroc.pl.