Indeed. Integers are implicitly casted to reals (of the same kind as the one on the other side of the operand) in such cases.
However, when writing if (x*x + y*y <= 1) then
, if the compiler is not smart enough the cast may happen at runtime.
Indeed. Integers are implicitly casted to reals (of the same kind as the one on the other side of the operand) in such cases.
However, when writing if (x*x + y*y <= 1) then
, if the compiler is not smart enough the cast may happen at runtime.
Interesting, so when performance matters it might be better to write 1._dp
to be sureā¦ But I also guess promoting an integer to a real may take just a negligible timeā¦
Has anybody tried to see if ChatGPT can recommend fpm packages?
The following news may be interesting for people working on the architecture of the fpm registry:
I donāt understand all the implications. But does it for example imply the packages should be signed?
For example, could the GSoC HTTP client project be used by such an attacker?
Probably this June 2020 discussion should be revisited:
Maybe we are at the crossroad with fpm.
@vmagnin I have tried the chatGPT for the fpm packages, but as the dataset used for training chatGPT was collected before 2021, it only knows about very early version of fpm ( alpha 0.1.0 ) it was able to give a brief idea of fpm and its setup (which was partially hallucinated / incorrect ) , it doesnāt know about registry and but It knows about the packages that were pre-existing like LAPACK, BLAS, NetCDF.
Regarding the chatGPTās package recommendations , although these can be very difficult to manipulate but can be possible if an attacker makes very large amount of occurrence on web regarding the package ( you could also just ask chatGPT to repeat davidjl123
and see its output , due this glitch token in chatGPT davidjl
and the story behind it.) .
I think signing a package will not be able to prevent this attack , as this is purely due to the bias in the dataset used for training the LLMs, one of the most possible way to prevent this could be to make our registry most accessible by most of the crawlers, indexers and also optimise it for SEO, so that it is easily collect the correct data. ( or release a dataset of the registry in form of archives which can be easily retrieved.) other way could be by moderation of fpm-registry ( this functionality has been implemented in the registry ).
The functioning of these tools will certainly evolve and we can think that they finally will be learning constantly from new content on the web.
In fact, I have posted my post here because that news was about ChatGPT and it made me think, but these concerns about security related to fpm, registry, etc. are of course more general. Fortran being used for example in big industries and Defense laboratories, I can imagine it could be a vector of attack for economic intelligence or State intelligence. And if ever it has never been done, it could be one more reason for an organisation to attack where it is not expected.
Could AI be a solution as well as a root of some problems? I think it highly likely an AI approach will soon be if not already part of virus scanning and evaluating packages of files for security risks. The data some virus scanning package producers have smells like a training dataset to me.
Yes, of course, it will ambivalent like all technologies. Each technology solves some problems and creates new ones. Humanity is co-evolving with its technologies. It is like a perpetual motion.
Itās always interesting to meditate on the last paragraph of the Nobel lecture of Pierre Curie (in English):
(1903 Nobel Prize concerning radioactivity: Henri Becquerel, Pierre Curie, Marie Curie)
I doubt generative AI will be seen as a fundamental discovery, I hope not.
Rather, there is a fair argument to be made some of these newer thingies such as generative AI - touted as ātechnologyā - are ideologies toward division of labor, no different perhaps than long followed labor-life practices were. Many new things came into conscience and reach - entire continents and new people on them - because of such ideologies but that did not make the approach toward labor any more justifiable nor beneficial in the larger scheme of things, in fact they have really proved to be morally reprehensible.
Yes, probably not a fundamental discovery but a powerful transformative tool, like the WWW and the social media, for better or worse.
I think I understand what you mean about division of labor. Itās related to what tech people call disruption. It seems everything must now be disrupted. Disruption is the new value. Of course, because it createsā¦ value for them.
The problem with those AI engines is that you need big computers and big databases to teach/feed them. In the 90ās, the disruption was on the other side: every computer fan could write a HTML page and disrupt centralized information (thanks CERN), or encode an MP3 and disrupt the music industry (thanks Fraunhofer).
Books on algorithms and numerical analysis often have pseudocode. A Wikipedia article presents a few styles of pseudocode and notes that pseudocode has not been standardized. If you write in a pseudocode that resembles Fortran, Python, R, or some mix of them, ChatGPT-4 can usually generate valid Fortran from it. I wonder if the Fortran community could agree on a syntax for a pseudocode that resembles Fortran but is shorter and simpler that special-purpose tools or LLMs could translate to standard Fortran. Syntax of interactive Fortran is a related thread from 2021.
ChatGPT-4 translates
do i = 1 to 16
if mod(i, 3) == 0 and mod(i, 5) == 0
print "fizzbuzz"
else if mod(i, 3) == 0
print "fizz"
else if mod(i, 5) == 0
print "buzz"
else
print i
end if
end do
to valid Fortran
program FizzBuzz
implicit none
integer :: i
do i = 1, 16
if (mod(i, 3) == 0 .and. mod(i, 5) == 0) then
print *, 'fizzbuzz'
else if (mod(i, 3) == 0) then
print *, 'fizz'
else if (mod(i, 5) == 0) then
print *, 'buzz'
else
print *, i
end if
end do
end program FizzBuzz
and does the same if do i=1, 16
is replaced by for i in 1:16
, terminated by next
instead of end do
.
It translates pseudocode to simulate pi
nran = 10^6
nin = 0
for i in 1:ran
x = rand()
y = rand()
if (x**2 + y**2) < 1
nin += 1
end if
next
print "pi =",4*nin/nran
to
program estimate_pi
implicit none
integer, parameter :: dp = kind(1.d0)
integer :: i, nran, nin
real(dp) :: x, y, pi_estimate
integer :: count, count_rate, count_max, seed_size
integer, allocatable :: seed(:)
call system_clock(count=count, count_rate=count_rate, count_max=count_max)
call random_seed(size=seed_size)
allocate(seed(seed_size))
seed = count * count_max / count_rate
call random_seed(put=seed)
nran = 10**6
nin = 0
do i = 1, nran
call random_number(x)
call random_number(y)
if ((x**2 + y**2) < 1) then
nin = nin + 1
end if
end do
pi_estimate = 4.d0 * nin / nran
print*, "pi =", pi_estimate
end program estimate_pi
admittedly after a few iterations of being fed gfortran error messages regarding its misuse of random_seed
In GitHub - Beliavsky/ChatGPT-Fortran-experiments: Experiments with ChatGPT to generate or find flaws in Fortran code ChatGPT-4 is able to find and fix the problem in most but not all small modern Fortran programs with the following flaws:
cpu_time()
put
argument with wrong size in random_seed()
real(kind=8)
intent(in)
and intent(out)
argumentstrim
optional
argument that is not present
Please send other small buggy programs to test ChatGPT on, especially those that pass gfortran -Wall -Wextra
.
One can use the openai
Python module to interact with ChatGPT. Having ChatGPT scan a code base could be a supplement to compiling with picky options and run-time testing, but I donāt know how good it is at spotting problems in larger codes or how many false positives it generates on code without problems.
It would be enlightening to have it review and maybe additionally comment the example programs for the intrinsics. They are short and do not have external dependencies. I expected a lot of reviews of those and the descriptions but only got a few volunteers so it would be interesting to me. Are those like what you had in mind? It might be good training material as well, as essentially each intrinsic is used.
I have a few thousand other short programs also used as man-page example programs; but they virtually all require an external dependency, as they are in fact describing the procedures in external libraries. A good number of them are in
Perplexity.ai is an LLM with search capabilities that cites its sources. Here is a sample conversation.
Q. Does Alan Miller have a Fortran code to compute a 1-D integral where the upper bound is plus infinity?
A. Yes, Alan Miller has a Fortran code to compute a 1-D integral where the upper bound is plus infinity. The code is available in his Fortran Software repository hosted on the CSIRO.au website. The specific code for adaptive one-dimensional integration over finite ranges, including the ability to compute the integral from minus infinity to plus infinity, can be found in the repository
2
.This code is adapted from TOMS algorithm 691 and is designed to solve a large set of n general linear equations using out-of-core methods, requiring storage for about n^2/4 values. The repository contains various Fortran codes for different numerical and statistical computations, including the adaptive one-dimensional integration code
1
.Q. I see qxgs.f90 Adaptive one-dimensional integration over finite ranges (adapted from TOMS algorithm 691), but I want a code for an infinite range.
A. Alan Millerās Fortran Software repository contains a code for handling integration over infinite intervals. The specific code for this purpose is the qagi.f90, which handles integration over infinite intervals by mapping the infinite range onto a finite interval and then applying a similar strategy as in the QAGS algorithm
5
. This code is part of the QUADPACK, a Fortran library for the numerical computation of definite one-dimensional integrals, and it is designed to handle integration over infinite intervals
1
.Therefore, if you are looking for a Fortran code to compute a 1-D integral where the upper bound is plus infinity, you can find the relevant code in Alan Millerās Fortran Software repository under the file name qagi.f90.
The suggestion of qagi.f90 is correct. The answer of ChatGPT 4 took longer to generate and is
I found some relevant information regarding Fortran code libraries that could be helpful in your search for a 1-D integral computation with an upper bound of plus infinity. However, there doesnāt seem to be a specific code by Alan Miller that exactly matches your description.
In the collection of Fortran libraries and code, there are various numerical integration tools and methods that might be adapted to your needs. For instance, the modernized QUADPACK Library for 1D numerical quadrature and the library for 1D-6D Adaptive Gaussian Quadrature could potentially be useful for your purposesāā.
Additionally, Alan Millerās Fortran Software includes a wide range of algorithms, some of which are related to statistical computations and numerical methods. While there isnāt a direct mention of a 1-D integral with an infinite upper bound, there are numerous other algorithms that might be of interest or could be adapted for your purposeāā.
For the specific task of computing a 1-D integral with an upper bound of infinity, you might need to look into adapting existing numerical integration libraries or algorithms. The detailed listings and descriptions of these libraries and codes could be a starting point for finding a suitable method or for further modification to meet your specific requirements.
The real answer, of course, is to use GitHub - jacobwilliams/quadpack: Modern Fortran QUADPACK Library for 1D numerical quadrature