Philip W. Brooks ([info]pbrooks) wrote,
@ 2005-10-12 16:02:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:prolog, silly

C is BAD
As part of a homework assignment a few years ago, I needed to be able to use Prolog to generate random numbers from a Gaussian (bell curve) distribution with a given mean and standard deviation. A friend found the code that does this in the Python standard library, so I translated it into Prolog.

When SWI Prolog 5.2.10 decompiles a compiled program, it names the first variable to occur A, the second B, and so on. Part of my translation of the Python looked like this in the source file:

gaussian(SD,Mean,R) :-
	gaussian_z(Z),
	!,
	retractall(gaussian_z(_)),
	R is Mean + SD * Z.
When compiled and displayed, it reads:
gaussian(A, B, C) :-
        gaussian_z(D), !,
        retractall(gaussian_z(E)),
        C is B+A*D.
In spite of its apparent dislike of the language, I've since translated this from Prolog into C (really, C++) for a quick and dirty Gaussian random number generator for use in SAGA.



(2 comments) - (Post a new comment)

Hey Filp
[info]skurvash
2005-10-13 02:53 am UTC (link)
Arrrg, 'tis yer brother. Dad pointed me towards your LJ, so I thought I'd drop by and make myself known. Talk you you soon. And tell Toby "I am Philip I am Philip I am Philip" Ciao for now.
-jb

(Reply to this)

I am Philip
[info]skurvash
2005-10-13 05:20 pm UTC (link)
Ask Toby if you really don't remember..

(Reply to this)


(2 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…