Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Your mode of life will be changed to EBCDIC.


devel / comp.lang.forth / Reentrancy and Multi-Dimensional Integration

SubjectAuthor
* Reentrancy and Multi-Dimensional IntegrationKrishna Myneni
`* Re: Reentrancy and Multi-Dimensional IntegrationMarcel Hendrix
 `- Re: Reentrancy and Multi-Dimensional IntegrationKrishna Myneni

1
Reentrancy and Multi-Dimensional Integration

<t1luqk$i22$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17395&group=comp.lang.forth#17395

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Reentrancy and Multi-Dimensional Integration
Date: Fri, 25 Mar 2022 21:46:42 -0500
Organization: A noiseless patient Spider
Lines: 86
Message-ID: <t1luqk$i22$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 26 Mar 2022 02:46:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="054d38a88b4e78f2d5a940890467cd6b";
logging-data="18498"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+l/p8bV1mWuCNCVaVTlZPe"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:mwkIjYl1qzd+qiFdF7iEhlNbL8c=
Content-Language: en-US
 by: Krishna Myneni - Sat, 26 Mar 2022 02:46 UTC

I ran into a limitation with the FSL module for performing N-point
Gauss-Legendre integration, gauleg.4th (FSL Algorithm #27). While the
existing algorithm is useful for numerically integrating one-dimensional
functions, it cannot be easily used for multi-dimensional integrals,
such as 2D integrals. A simple example is integrating the 2D function,

f(x, y) = x^2 + y^2

over the rectangle defined by x: 0->2 and y: 0->1. This integral may
easily be evaluated analytically to obtain the answer, 3 1/3.

The basic problem with the implementation of the integrator,

)GL-INTEGRATE

is that it is not reentrant. Thus, in a 2D integral, the instance of
)GL-INTEGRATE used to perform outer integral, say over x, cannot call
)GL-INTEGRATE to perform the inner integral over y. This is evident
because )GL-INTEGRATE stores information about the integrand function
and the arrays containing abscissas and weights for N-point
Gauss-Legendre integration in external variables:

---
: )gl-integrate ( func &x &w n -- z )

\ validate the parameter N
DUP 1 < ABORT" bad value of N (must be > 0) for )gl-integrate "

>R
& w{ &! & x{ &! is f(x)

0.0E0
R> 0 DO
x{ I } F@ f(x)
w{ I } F@ F*
F+
LOOP
; ---

This word may be rewritten to be re-entrant as follows:
---
: )gl-integrate ( func &x &w n -- z )
\ validate the parameter N
DUP 1 < ABORT" bad value of N (must be > 0) for )gl-integrate "
0.0E0
0 DO \ func &x &w ; F: rsum
over I } F@ 2 pick execute
dup I } F@ F*
F+ \ func &x &w ; F: rsum2
LOOP
2drop drop ;
---

The simple example may be evaluated using the revised )GL-INTEGRATE --
the code may be found at the link,

https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/demo/2D_integral_01.4th

The revised version of gauleg.4th, allowing for the integrator to be
reentrant, may be found at

https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/gauleg.4th

---
$ kforth64

include 2D_integral_01.4th

Type 'integral_xy fs.' to compute the 2D integral of
the function, f[x, y] = x^2 + y^2, over the rectangular
region: x: 0 -> 2, y: 0 -> 1

ok
integral_xy fs.
3.33333333333332e+00 ok
---

--
Krishna Myneni

Re: Reentrancy and Multi-Dimensional Integration

<80a2f4f4-aca8-495d-a20c-afe46f2a3f36n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17396&group=comp.lang.forth#17396

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5a95:0:b0:2e2:e4f:63c with SMTP id c21-20020ac85a95000000b002e20e4f063cmr13273384qtc.537.1648282997438;
Sat, 26 Mar 2022 01:23:17 -0700 (PDT)
X-Received: by 2002:ad4:5fcf:0:b0:441:5f3:65ab with SMTP id
jq15-20020ad45fcf000000b0044105f365abmr12464382qvb.87.1648282997308; Sat, 26
Mar 2022 01:23:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 26 Mar 2022 01:23:17 -0700 (PDT)
In-Reply-To: <t1luqk$i22$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f14:600:8b3:1a65:d983:2995;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f14:600:8b3:1a65:d983:2995
References: <t1luqk$i22$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <80a2f4f4-aca8-495d-a20c-afe46f2a3f36n@googlegroups.com>
Subject: Re: Reentrancy and Multi-Dimensional Integration
From: mhx...@iae.nl (Marcel Hendrix)
Injection-Date: Sat, 26 Mar 2022 08:23:17 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 21
 by: Marcel Hendrix - Sat, 26 Mar 2022 08:23 UTC

On Saturday, March 26, 2022 at 3:46:46 AM UTC+1, Krishna Myneni wrote:
> I ran into a limitation with the FSL module for performing N-point
> Gauss-Legendre integration, gauleg.4th (FSL Algorithm #27).

I had somewhat of the reverse problem when making the NRC library
available to iForth. Some of the NRC functions, e.g. the
Davidon-Fletcher-Powell algorithm, work with function pointers.
This means C will call Forth code.

As the data transfer in the NRC is mostly done with matrices,
a Forth word in the callback must keep its state (easy: use the
stack or locals) and dynamically allocate memory for the needed
matrices. The word must be careful when calling NRC
functions when it executes, but luckily these C functions are
re-entrant already (iForth does not support the Fortran NRC :-)

There is of course a real problem when a Forth word being
callbacked calls non-re-entrant other Forth words, but this is
relatively straight-forward and something the programmer will
have to take care of himself.

-marcel

Re: Reentrancy and Multi-Dimensional Integration

<t1n6iq$tor$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17397&group=comp.lang.forth#17397

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Reentrancy and Multi-Dimensional Integration
Date: Sat, 26 Mar 2022 09:05:12 -0500
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <t1n6iq$tor$1@dont-email.me>
References: <t1luqk$i22$1@dont-email.me>
<80a2f4f4-aca8-495d-a20c-afe46f2a3f36n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 26 Mar 2022 14:05:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="054d38a88b4e78f2d5a940890467cd6b";
logging-data="30491"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xXoFM6RYLy75NAik2ZZ3J"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:nw//ON3BkjS0dk02dzsiV17ugS4=
In-Reply-To: <80a2f4f4-aca8-495d-a20c-afe46f2a3f36n@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Sat, 26 Mar 2022 14:05 UTC

On 3/26/22 03:23, Marcel Hendrix wrote:
> On Saturday, March 26, 2022 at 3:46:46 AM UTC+1, Krishna Myneni wrote:
>> I ran into a limitation with the FSL module for performing N-point
>> Gauss-Legendre integration, gauleg.4th (FSL Algorithm #27).
>
> I had somewhat of the reverse problem when making the NRC library
> available to iForth. Some of the NRC functions, e.g. the
> Davidon-Fletcher-Powell algorithm, work with function pointers.
> This means C will call Forth code.
>

Do you provide a compiled C library of the NRC routines?

I've spent a lot of time in the past interfacing Forth (kForth-32) to
external C and Fortran libraries. For most of my needs these days, it's
better off to work with Forth source libraries, and, when efficiency is
required, a mix of Forth source and assembly language. If it's too
daunting a task to write a Forth source library, I will work in another
language. But, having a Forth source library makes the code immensely
more valuable for study (interactively from the Forth environment) and
to modify to suit my particular computing need.

> As the data transfer in the NRC is mostly done with matrices,
> a Forth word in the callback must keep its state (easy: use the
> stack or locals) and dynamically allocate memory for the needed
> matrices. The word must be careful when calling NRC
> functions when it executes, but luckily these C functions are
> re-entrant already (iForth does not support the Fortran NRC :-)
>
> There is of course a real problem when a Forth word being
> callbacked calls non-re-entrant other Forth words, but this is
> relatively straight-forward and something the programmer will
> have to take care of himself.
>

I don't think the FSL algorithms have undergone much scrutiny for
reentrancy problems, in cases where there is a possibility of occurring.
I expect that such cases are unusual. It is not likely, for example,
that a matrix inversion algorithm needs to be reentrant, but there may
be cases for block diagonal matrices.

--
Krishna

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor