On Fri, Jun 26, 2026 at 09:58:13PM +0800, Qian Yun wrote:
> On 6/26/26 9:38 PM, Waldek Hebisch wrote:
> > On Fri, Jun 26, 2026 at 08:12:44PM +0800, Qian Yun wrote:
> >> On 6/26/26 7:37 PM, Waldek Hebisch wrote:
> >>>
> >>>> Thus, when inserting a non-algebraic new kernel, if the binary
> >>>> search returns no match, then we are sure it is a new kernel,
> >>>> we can insert it directly without the need to do linear search.
> >>>>
> >>>> The above analysis is sound, right?
> >>>
> >>> I do not think so. Not having true order means potential lack
> >>> of transitivity. So kernel that we look for may be in almost
> >>> any position relative to kernels in the path of binary search.
> >>>
> >>
> >> Assuming in a session we only have non-algebraic kernels.
> >> Then current order is a true order.
> >
> > Yes.
> >
> >> Now considering adding some algebraic kernels.
> >> Then "smaller?" as lexicographical order, is still a true order.
> >
> > It is not clear to me what you mean here.
>
> For 2 expression ea and eb, we may have smaller?(ea,eb) is true
> but ea=eb is also true.
>
> Now for the kernels already in the cache: ka and kb, they are
> never equal, and when coerced into EXPR, they have "smaller?"
> as the true order.
I am affraid you jump to conclusions without justification.
IIRC we had an example of expression such that smaller?(c, a)
holds, but we also have smaller?(a, b) and smaller?(b, c).
In such case and assuming b is in the cache and used for
binary search a will be inserted below b and c will be
inserted above b. Later search for a may find c on its
path and conseqently binary search will look for a
above c so above b, that is in wrong part.
More generally, let us assume subset K0 of "nice" kernels.
AFAICS validity of binary search for K0 implies the
following: for each kernels a, c in K0 such that smaller?(a, b)
and each c in K we have two implications:
- smaller?(c, a) implies smaller?(c, b)
- smaller?(b, c) implies smaller?(a, c)
AFAICS this in only necessary condition, sufficient condition
looks much more complicated.
> >> It's the involvement of "=" makes two lexicographical different
> >> expression/kernel the same, making the latter inputted one
> >> automatically transform to firstly inputted one.
> >
> > And here.
> >
> >> But the result of kernel cache is still a true order,
> >> if we are comparing a non-algebraic kernel to them.
> >
> > Only if there are no comparisons with algebraic kernels.
> >
>
> Now for a new non-algebraic kernel kc, if the binary search shows
> no equals, then we can say it is not in the kernel cache,
> because the kernel cache is strictly ordered by "smaller?".
You may be confused by how 'smaller?' works. Kernels in the
cache are ordered by position, this is linear order. 'smaller?'
for kernels just uses position, so also is linear order. But
insertion uses 'triage'. If triage were linear order, then
kernels would be sorted with respect to 'triage'. But since
'triage' is not a linear order 'smaller?' and 'triage' may
give differnt results. Since for insertion we use 'triage',
fact that 'smaller?' is a linear order on kernels does not
help much.
Also, not that 'triage?' uses 'smaller?' for expression.
If you have kernels like 'sin(e1)', 'sin(e2)', ... etc,
'triage(sin(ei), sin(ej)' will be -1 if and only if
'smaller?(ei, ej)' holds. So 'triage' has the same
problems as 'smaller?' for expressions.
--
Waldek Hebisch