Re: [xsl] Math "functions" for XSLT 1.0

Subject: Re: [xsl] Math "functions" for XSLT 1.0
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 3 Mar 2010 19:37:55 -0800
> By the way, almost 30 years ago, I already knew that calculators never use
> Taylor series (CORDIC algorithms were written in 1959)... Even if they are
> mathematically correct, they require too many iterations for small systems
> and managing huge numbers such as factorials is not always possible. I'm
> interested in XSLT at browser side and speed is important.


I must comment on one other mis-statement here: " Even if they are
mathematically correct, they require too many iterations for small
systems and managing huge numbers such as factorials is not always
possible"

I want to assure our readers that nowhere in the FXSL implementation
of sin() (or any other Taylor series - based implementation), there
are " huge numbers such as factorials".

I don't think even a naive freshman implementation would use
"factorials". To be up to the point, the following 25 lines contain
the most significant template that carries out the sin() calculation
-- do you see a factorial anywhere?

  <xsl:template name="_sineIter">
    <xsl:param name="pX2"/>
    <xsl:param name="pRslt"/>
    <xsl:param name="pElem"/>
    <xsl:param name="pN"/>
    <xsl:param name="pEps"/>
    <xsl:variable name="vnextN" select="$pN+2"/>
    <xsl:variable name="vnewElem" select="-$pElem*$pX2 div
($vnextN*($vnextN - 1))"/>
    <xsl:variable name="vnewResult" select="$pRslt + $vnewElem"/>
    <xsl:variable name="vdiffResult" select="$vnewResult - $pRslt"/>
    <xsl:choose>
      <xsl:when test="$vdiffResult > $pEps or $vdiffResult &lt; -$pEps">
        <xsl:call-template name="_sineIter">
          <xsl:with-param name="pX2" select="$pX2"/>
          <xsl:with-param name="pRslt" select="$vnewResult"/>
          <xsl:with-param name="pElem" select="$vnewElem"/>
          <xsl:with-param name="pN" select="$vnextN"/>
          <xsl:with-param name="pEps" select="$pEps"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$vnewResult"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

The full code may be viewed here:


http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-trignm.xsl?revi
sion=1.3&view=markup


--
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
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Wed, Mar 3, 2010 at 10:49 AM, COUTHURES Alain
<alain.couthures@xxxxxxxxxxxxx> wrote:
> Dimitre,
>
> Unfortunately, FXSL is not in first results listed by Google when searching
> "xslt sin" or "xslt cos".
>
> By the way, almost 30 years ago, I already knew that calculators never use
> Taylor series (CORDIC algorithms were written in 1959)... Even if they are
> mathematically correct, they require too many iterations for small systems
> and managing huge numbers such as factorials is not always possible. I'm
> interested in XSLT at browser side and speed is important.
>
> So, if FXSL users consider it good enough for their requirements, it's good
> to know. Do you know if they are working at client-side or at server-side ?
>
> Because I spent no more than one day to find algorithms and less than one
> another to implement the ones I need, it wasn't for me a costly effort,
> anyway.
>
> If only Microsoft had already implemented XSLT 2.0, XPath 2.x, SVG,
> XForms,... more efforts would have been saved...
>
> Best regards,
>
> -Alain

Current Thread