Do you know any other example with some explanations?

By advance, thanks for your help.

Statistics: Posted by phdenis40 — Sun Aug 28, 2016 7:21 am

]]>

Can anyone review my code? This is exercise 1.28 from SICP.

Description:

"Exercise 1.28: One variant of the Fermat test that cannot be fooled is called the Miller-Rabin test (Miller 1976; Rabin 1980). This starts from an alternate form of Fermat’s Little Theorem, which states that if n is a prime number and a is any positive integer less than n, then a raised to the n-1-st power is congruent to 1 modulo n. To test the primality of a number n by the Miller-Rabin test, we pick a random number a < n and raise a to the n-1-st power modulo n using the expmod procedure. However, whenever we perform the squaring step in expmod, we check to see if we have discovered a “nontrivial square root of 1 modulo n,” that is, a number not equal to 1 or n-1 whose square is equal to 1 modulo n. It is possible to prove that if such a nontrivial square root of 1 exists, then n is not prime. It is also possible to prove that if n is an odd number that is not prime, then, for at least half the numbers a < n, computing a^n-1 in this way will reveal a nontrivial square root of 1 modulo n. (This is why the Miller-Rabin test cannot be fooled.) Modify the expmod procedure to signal if it discovers a nontrivial square root of 1, and use this to implement the Miller-Rabin test with a procedure analogous to fermat-test. Check your procedure by testing various known primes and non-primes. Hint: One convenient way to make expmod signal is to have it return 0."

https://mitpress.mit.edu/sicp/chapter1/node17.html

Here is my code:

(define (square x) (* x x))

(define (expmod base exp m)

(define (expmod-iter a base exp)

(define squareMod (remainder (square base) m))

(cond ((= exp 0) a)

((and (not (= base (- m 1)))

(not (= base 1))

(= squareMod 1))

0)

((even? exp)

(expmod-iter

a

squareMod

(/ exp 2)))

(else

(expmod-iter

(remainder (* a base) m)

base

(- exp 1)))))

(expmod-iter

1

base

exp))

(define (miller-rabin-test n)

(define (try-it a)

(= (expmod a n n) 1))

(try-it (+ 1 (random (- n 1)))))

(define (fast-prime? n times)

(cond ((= times 0) true)

((miller-rabin-test n)

(fast-prime? n (- times 1)))

(else false)))

http://paste.lisp.org/display/323708

Did I follow the exercise? Is this correct? Are there bugs? Thanks for any feeback!

Statistics: Posted by morbidCode — Fri Aug 26, 2016 2:49 am

]]>

215.215 2154.2 144.213 2352.235 201.1 2354.32 ...

How can I read each number in order to draw that polyline?

Note: the coordinates line alternate between the X coordinate and Y coordinate.

Thank for your seggestions.

Statistics: Posted by maczinc — Wed Aug 24, 2016 3:30 am

]]>

]]>

pjstirling wrote:

sbcl won't run with ASLR.

sbcl won't run with ASLR.

That makes SBCL a bad choice for server applications. Is there a way to circumvent this? Is a patch upcoming?

Statistics: Posted by Lispeth — Mon Aug 22, 2016 10:05 am

]]>

]]>

I'm starting with Lisp doing simple things to practice but I have a problem with this routine that I can not get it to work .

I want to do is to draw a line , this line will automatically extend to the nearest point .

the problem is that when using two ( getpoint ) can not use Ortho to go straight , plus the line must go from right to left to run the " extend" command or from the top down

Try using the " line " command without giving values but at the end of the command no longer continues to extend

This is the routine is very simple please do not laugh xD

(defun c:LE()

(command "pline" (getpoint) (getpoint) "")

(setq s1 (ssget "l"))

(command "extend" "" s1 "")

(princ)

)

I do not put image because it is something very simple

It is to use the " line " command and " extend" at the same time

Statistics: Posted by adnegel — Sat Aug 20, 2016 8:45 am

]]>

]]>

From time to time, I find myself wanting to use MAPCAR where the function would like to make use of the index. I've done it in some kind of stupid ways in the past, and then came up with this:

- Code:
`(defun make-counter ()`

(let ((count 0))

(lambda ()

(prog1 count (incf count)))))

(defun make-counter-circle ()

(alexandria:make-circular-list 1 :initial (make-counter)))

(mapcar (lambda (n x)

(list (funcall n) x))

(make-counter-circle)

'(a b c d e f g))

=> ((0 A) (1 B) (2 C) (3 D) (4 E) (5 F) (6 G))

I can't see anything obviously wrong with it, but I don't think I've seen this before.

Is this sensible? A known pattern? A world-changing work of inspired genius? "Not even wrong"?

Statistics: Posted by garethw — Thu Aug 11, 2016 7:24 am

]]>

- Code:
`[1]> (find-package "USER")`

#<PACKAGE COMMON-LISP-USER>

COMMON-LISP-USER is explicitly allowed to include whatever implementation-specific symbols (that don't conflict with those of COMMON-LISP) that the implementation likes, for clisp that includes the symbols from EXT, which unhappily for this case, includes EXT:EXECUTE.

I've not investigated your theorem prover's code, but by using an implementation package and not defining its own is indeed the cause of the problem, as that comment states, but the comment also implies that the author had no real understanding of how to write portable code that could selectively call implementation specific behaviour (d'oh!)

I think some kind of source surgery is necessary, though probably creating a proper package is the right change rather than simply renaming the EXECUTE function (though potentially a little more work).

Statistics: Posted by pjstirling — Tue Aug 09, 2016 2:12 pm

]]>