Search found 183 matches

by cameyo
Fri Sep 20, 2019 6:25 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

Thanks, Lutz !
Grazie Lutz !
by cameyo
Fri Sep 20, 2019 4:29 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

Thanks Lutz. Anyway i have found a strange thing: raising an error on REPL reset the time. For example, type the following on REPL: (set) ERR: missing argument in function set Now timing the function will restart the problem (but time is reset to first value 1750.432): (time (merge (sequence 1 500) ...
by cameyo
Fri Sep 20, 2019 2:52 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

@Lutz: Seems to me that you test the wrong function: (define (merge lstA lstB op) (sort (append lstA lstB) op)) This works well. The "time growing" problem arise with the following two functions : (define (merge lstA lstB op) (define (ciclo out lstA lstB) (cond ((null? lstA) (extend (reverse out) l...
by cameyo
Fri Sep 20, 2019 1:15 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

@rickyboy:
i'm trying to solve the problem of time growing. I know that the Scheme style is not good for newLISP.
And yes, i'm a student...forever :-)
Thanks for the help.
by cameyo
Fri Sep 20, 2019 6:01 am
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

@rickyboy and @ralph.ronnquist
Sorry, I didn't explain myself well. The function i tried was "merge" with temporary heap function.
The function with sort works well.
By the way, the fastest function is "merge-via-loop".
Thanks.
by cameyo
Thu Sep 19, 2019 6:00 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

@ralph.ronnquist: I have tried your function (in a fresh REPL), but the result are the same: > (time (merge (sequence 1 500) (sequence 1 200) <) 500) 1842.392 > (time (merge (sequence 1 500) (sequence 1 200) <) 500) 2290.107 > (time (merge (sequence 1 500) (sequence 1 200) <) 500) 2831.184 > (time ...
by cameyo
Thu Sep 19, 2019 10:08 am
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

Thanks for the info.
btw. what's wrong with:
(define (merge lstA lstB op) (sort (append lstA lstB) op))
Nothing :-) It's ok.
But I would like to know the cause of the problem.
Have a nice day.
by cameyo
Thu Sep 19, 2019 7:37 am
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Re: Timing function problem

Thanks Rickyboy.
I known, the Scheme style is not suitable for newLISP :-)
But I'd like to know what creates the problem.
Time function or my merge function?
Have a nice day
by cameyo
Wed Sep 18, 2019 12:26 pm
Forum: newLISP in the real world
Topic: Timing function problem
Replies: 19
Views: 13440

Timing function problem

I have a problem with the following function who merge two ordered lists in a new list. (define (merge lstA lstB op) (define (ciclo out lstA lstB) (cond ((null? lstA) (extend (reverse out) lstB)) ((null? lstB) (extend (reverse out) lstA)) ((op (first lstB) (first lstA)) (ciclo (cons (first lstB) out...
by cameyo
Tue Sep 17, 2019 9:35 am
Forum: newLISP in the real world
Topic: Check if a number is a perfect power
Replies: 0
Views: 4704

Check if a number is a perfect power

A perfect power is a number n of the form m^k, where m>1 is a positive integer and k>=2. If the prime factorization of n is n=p1^(a1)*p2^(a2)...pk^(ak), then n is a perfect power iff GCD(a1,a2,...,ak) > 1. The "factor-exp-list" function calculates the list of exponents of the factorization of the nu...
by cameyo
Tue Sep 10, 2019 3:38 pm
Forum: newLISP in the real world
Topic: Wheel factorization for big integer
Replies: 0
Views: 4816

Wheel factorization for big integer

For theory see: https://en.wikipedia.org/wiki/Wheel_factorization (define (factorbig n) (local (f k i dist out) ; Distanze tra due elementi consecutivi della ruota (wheel) (setq dist (array 48 '(2 4 2 4 6 2 6 4 2 4 6 6 2 6 4 2 6 4 6 8 4 2 4 2 4 8 6 4 6 2 4 6 2 6 6 4 2 4 6 2 6 4 2 4 2 10 2 10))) (set...
by cameyo
Thu Sep 05, 2019 3:18 pm
Forum: newLISP in the real world
Topic: Carmichael numbers
Replies: 0
Views: 4708

Carmichael numbers

In number theory, a Carmichael number is a composite number n which satisfies the modular arithmetic congruence relation: b^(n-1) ≡ 1 mod n for all integers b which are relatively prime to n. https://en.wikipedia.org/wiki/Carmichael_number (define (fattorizza x) (letn (fattori (factor x) unici (uniq...
by cameyo
Thu Sep 05, 2019 1:34 pm
Forum: newLISP in the real world
Topic: Every odd integer is the difference of 2 squares
Replies: 0
Views: 4625

Every odd integer is the difference of 2 squares

Try this: (define (breaknum n) (if (even? n) nil (list (* (- n (/ n 2)) (- n (/ n 2))) (* (/ n 2) (/ n 2)) ))) (breaknum 11) ;-> (36 25) (breaknum 9527) ;-> (22695696 22686169) Proof 1) Pick an odd number (5): OOOOO 2)Bend it in half: OOO O O 3) Fill the rest: OOO OXX OXX The odd number is the area ...
by cameyo
Fri Aug 30, 2019 8:18 am
Forum: newLISP in the real world
Topic: Twin primes
Replies: 3
Views: 3727

Re: Twin primes

Thanks ralph.ronnquist. This is faster than mine :-)
Have a nice day.
by cameyo
Wed Aug 28, 2019 2:14 pm
Forum: newLISP in the real world
Topic: Twin primes
Replies: 3
Views: 3727

Twin primes

Two functions to calculate twin primes (pairs and pairs-i). (define (prime? n) (if (even? n) nil (= 1 (length (factor n))))) (define (twin? n) (if (and (prime? n) (prime? (+ n 2))) (list n (+ n 2)) nil)) (twin? 9) ;-> nil (twin? 881) ;-> (881 883) (define (pairs a b) (filter true? (map twin? (sequen...
by cameyo
Mon Aug 26, 2019 8:23 am
Forum: newLISP in the real world
Topic: Create polynomials
Replies: 3
Views: 3888

Re: Create polynomials

Thanks ralph.ronnquist.
I'm looking for a simple way to build "Lagrange Polynomial Interpolation". It is a bit more complex than polynomials.
Have a nice day.
cameyo
by cameyo
Sun Aug 25, 2019 3:45 pm
Forum: newLISP in the real world
Topic: Create polynomials
Replies: 3
Views: 3888

Create polynomials

Suppose we have the polynomial y (x) = 3*x^2 - 7*x + 5 and we want to calculate the values of y for x ranging from 0 to 10 (with step 1). We can define a function that represents the polynomial: (define (poly x) (+ 5 (mul 7 x) (mul 3 (pow x 2)))) (poly 0) ;-> 5 And then to get the searched values: (...
by cameyo
Mon Jul 22, 2019 10:21 am
Forum: newLISP in the real world
Topic: Church encoding
Replies: 2
Views: 3102

Re: Church encoding

@kosh: thanks. I'll study it as soon as possible.
by cameyo
Sun Jul 21, 2019 2:59 pm
Forum: newLISP in the real world
Topic: Church encoding
Replies: 2
Views: 3102

Church encoding

In the Church encoding of natural numbers, the number N is encoded by a function that applies its first argument N times to its second argument. Church zero always returns the identity function, regardless of its first argument. In other words, the first argument is not applied to the second argumen...
by cameyo
Sun Jul 14, 2019 9:55 am
Forum: newLISP in the real world
Topic: Pathological floating point problems
Replies: 2
Views: 3081

Re: Pathological floating point problems

Thanks rickyboy.
I'll use your rational functions ;-)
by cameyo
Sat Jul 13, 2019 3:12 pm
Forum: Whither newLISP?
Topic: pseudo-random number generator
Replies: 1
Views: 4550

pseudo-random number generator

Which type of pseudo-random number generator uses newLISP?
Thanks.
by cameyo
Sat Jul 13, 2019 1:49 pm
Forum: newLISP in the real world
Topic: Pathological floating point problems
Replies: 2
Views: 3081

Pathological floating point problems

From https://rosettacode.org/wiki/Pathological_floating_point_problems Problem The Chaotic Bank Society is offering a new investment account to their customers. You first deposit $ (e - 1) where "e" is 2.7182818 (the base of natural logarithms). After each year, your account balance will be multipli...
by cameyo
Wed Jul 03, 2019 1:57 pm
Forum: newLISP in the real world
Topic: Karatsuba algorithm
Replies: 0
Views: 4586

Karatsuba algorithm

From: https://en.wikipedia.org/wiki/Karatsuba_algorithm (define (potenza n m) (let (pot 1L) (dotimes (x m) (setq pot (* pot n)))) ) (potenza 3 6) ;-> 729L Iterative: (define (karatsuba num1 num2) (local (m m2 high1 low1 high2 low2 z0 z1 z2) (cond ((or (< num1 10) (< num2 10)) (* num1 num2)) (true (s...
by cameyo
Sun Jun 30, 2019 2:12 pm
Forum: newLISP in the real world
Topic: Maze solution
Replies: 0
Views: 4517

Maze solution

From: https://en.wikipedia.org/wiki/Maze_solving_algorithm The recursive solution with newLISP: (define (solveMaze matrice sRow sCol eRow eCol) (local (maze row col visited correctPath starRow startCol endRow endCol) ; matrice labirinto (setq maze matrice) ; righe della matrice (setq row (length maz...
by cameyo
Sun Jun 16, 2019 10:14 am
Forum: newLISP in the real world
Topic: initializer expressions by a predefined list in "let"
Replies: 3
Views: 3608

Re: initializer expressions by a predefined list in "let"

(setq a 1 b 2) (let (l (+ a b)) (println l)) ;-> 3 (let (a 4 b 5 l (+ a b)) (println a { } b { } l)) ;-> 4 5 3 ; l = 3 because in the expression (+ a b), a = 1 and b = 2. Use letn to solve this: (letn (a 4 b 5 l (+ a b)) (println a { } b { } l)) ;-> 4 5 9 ; Now l = 9 because inside the letn express...