On Mon, Dec 07, 2020 at 06:57:08PM +0800, Qian Yun wrote:
>
>
> On 12/5/20 11:26 PM, Waldek Hebisch wrote:
> > On Sat, Dec 05, 2020 at 09:06:22PM +0800, oldk1331 wrote:
> > > Almost sure it is bug when adding new kernel in cache, in function
> > > "enterInCache".
> >
> > ATM our handling of kernel cache is unsound. Basicaly, kernel
> > cache assumes order and in fact there are no consistent order
> > on kernels. Many problems would go away if we would switch
> > to linear search for kernels (awoiding use of order). But
> > that would slow down unormously routines making heavy
> > use of kernels (mainly series expansion and limits). And
> > some problem would remains.
>
> In 2015 March 20, email titled "Re: Troubles with kernels",
> you said:
>
> > There is potential problem with binary search that we use.
> > Linear search trough all of the cache should work fine.
> > Surprisingly after fixing a few other bugs I was not able to
> > produce example of failure due to wrong sort, so I keep it
> > as is.
>
> Do you have other failure examples since then?
IIRC Kurt Pagani gave most striking example.
> > I expect that sooner or later problem will show up,
> > then we will have to think about solution. One possibility is
> > to use linear search, which is slow. Another possibility is
> > to force removal of irrationalities from denominators.
> > That would make representation canonical and allow
> > sorting/hashing at representation level.
>
> To record the problem we encountered this time, it boils down to
>
> y := (complex(0,1)*x*exp((complex(0,2)*x)/complex(1,0))+complex(-1,0)*x)/(complex(1,1)*exp((complex(0,2)*x)/complex(1,0))+complex(1,1))
>
> a := (complex(0,-1)*exp((complex(0,1)*x)/complex(1,0))^2+complex(0,-1))/(complex(2,0)*exp((complex(0,1)*x)/complex(1,0)))
>
> b := (complex(-2,0)*exp((complex(0,1)*x)/complex(1,0)))/(complex(1,0)*exp((complex(0,1)*x)/complex(1,0))^2+complex(-1,0))
>
> And smaller?(y,a) smaller?(a,b) smaller?(b,y) are all true,
> causing it impossible to order kernel exp(y),exp(a),exp(b).
The expressions are transcendental and 'smaller?' should work
for them. OTOH inside integrator 'exp(2*%i*x)' and 'exp(%i*x)'
should not appear together, 'normalize' removes first one
and no other routine should introduce new unnormalizes
kernels. Unfortunaltely, some routines do this and
we need to replace them by correct ones.
> About possible solution: we can do better than linear search,
> we should be able to classify kernels into groups, and groups
> are strictly ordered. Then search and insert of kernel into
> cache would be quicker.
Well, I have looked at various possible schemes. ATM it
is not clear for me which one is better. Basicaly, my
current view is that integrator should internaly use
representation which is significantly different than
current Expression. In particular it should keep its
own represention of kernels _for given problem_.
Currently when integration problem after normalization
involves more than 20-30 kernels, then it is way too hard.
So probably integrator could do linear search (searches
in integrator should be relatively rare compared to
other operations). OTOH, having control over kernels
integrator could speed up searches. Important point
is that after integration problem is done integrator
would discard all info about kernels, so there would
be no problem with maintaining consistency between
successive calls.
Assuming the above is sucessful, we could than use similar
approach in other heavy users of kernels. And turn
Expression into a wrapper for user convenience. But
ATM I am at very first stage...
--
Waldek Hebisch