xsl-list
[Top] [All Lists]

Re: [xsl] Increasing sequence ?

2015-03-26 23:24:00
Hi Leo,

I ran this with BaseX 7.8.2:

declare namespace my = "my:my";
declare function my:increasing($seq as xs:double*) as xs:boolean
 {empty($seq[2])
 or
  $seq[1] lt $seq[2]  and  my:increasing(subsequence($seq, 2))
 };
let $v:=(1 to 10000)
  return my:increasing($v)


And here is the result (do note this below: - marking as ***tail
call***: my:increasing(fn:subsequence($seq_0, 2))  )

Total Time: 3.74ms (for 100 000 - long sequence the time was 17.77ms,
for 1 000 000 - long sequence the time was 207.56ms)

Compiling:
- removing redundant xs:boolean cast.
- marking as tail call: my:increasing(fn:subsequence($seq_0, 2))
- pre-evaluating (1 to 10000)
- inlining let $v_1 := (1 to 10000)
- simplifying flwor expression
Query:
declare namespace my = "my:my"; declare function my:increasing($seq as
xs:double*)as xs:boolean {empty($seq[2]) or $seq[1] lt $seq[2] and
my:increasing(subsequence($seq, 2)) }; let $v:=(1 to 10000) return
my:increasing($v)
Optimized Query:
declare function my:increasing($seq_0 as xs:double*) as xs:boolean {
(fn:empty($seq_0[2]) or (($seq_0[1] lt $seq_0[2]) and
my:increasing(fn:subsequence($seq_0, 2)))) };
my:increasing((1 to 10000))
Result:
- Hit(s): 1 Item
- Updated: 0 Items
- Printed: 4 Bytes
- Read Locking: none
- Write Locking: none
Timing:
- Parsing: 0.91 ms
- Compiling: 0.19 ms
- Evaluating: 2.5 ms
- Printing: 0.14 ms
- Total Time: 3.74 ms
Query plan:
<QueryPlan>
  <StaticFunc name="my:increasing" arg0="seq">
    <Or tailCall="true">
      <FNSimple name="empty(item)">
        <IterPosFilter>
          <VarRef>
            <Var name="$seq" id="0" as="xs:double*"/>
          </VarRef>
          <Pos min="2" max="2"/>
        </IterPosFilter>
      </FNSimple>
      <And tailCall="true">
        <CmpV op="lt">
          <IterPosFilter>
            <VarRef>
              <Var name="$seq" id="0" as="xs:double*"/>
            </VarRef>
            <Pos min="1" max="1"/>
          </IterPosFilter>
          <IterPosFilter>
            <VarRef>
              <Var name="$seq" id="0" as="xs:double*"/>
            </VarRef>
            <Pos min="2" max="2"/>
          </IterPosFilter>
        </CmpV>
        <StaticFuncCall name="Q{my:my}increasing" tailCall="true">
          <FNSeq name="subsequence(items,start[,len])">
            <VarRef>
              <Var name="$seq" id="0" as="xs:double*"/>
            </VarRef>
            <Int value="2" type="xs:integer"/>
          </FNSeq>
        </StaticFuncCall>
      </And>
    </Or>
  </StaticFunc>
  <StaticFuncCall name="Q{my:my}increasing" tailCall="false">
    <RangeSeq from="1" to="10000"/>
  </StaticFuncCall>
</QueryPlan>

On Thu, Mar 26, 2015 at 12:48 PM, Dimitre Novatchev
<dnovatchev(_at_)gmail(_dot_)com> wrote:
 Leo,

I tried it with an xQuery function (I know it does not belong here ;-)) and
had a stack problem with a sequence with 10000 elements ;-( (Oxygen 16.1)

I think I know what the issue is most likely.

I can investigate further only after I am back at home from work, but
my guess is that if you use BaseX, there will be no SO problem.


Cheers,
Dimitre




On Thu, Mar 26, 2015 at 12:40 PM, Leo Studer 
leo(_dot_)studer(_at_)varioweb(_dot_)ch
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Dimitre

the question came up in a XML Schema 1.1 assertion where only xPath 2.0
expressions are allowed.

Dimitre, yes, this is nice, however can not be used in xsd:assertions.


Do you mean that you cannot use an XSLT function?

And there is a stack problem with large sequences.


I tried it with an xQuery function (I know it does not belong here ;-)) and
had a stack problem with a sequence with 10000 elements ;-( (Oxygen 16.1)


There shouldn't be such problem with this particular function, if the
XSLT processor recognizes and optimizes tail recursion.


Always
Leo
XSL-List info and archive
EasyUnsubscribe (by email)



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>