The LUNAR simulator in Shen

636 views
Skip to first unread message

Antti Ylikoski

unread,
Oct 9, 2015, 3:50:34 PM10/9/15
to Shen
Hi,

I did in Shen the classic LUNAR moon landing simulator.

As you ppl most probably know, this one has been in innumerable
computers ever since the 1970's.

It is not only mere fun -- It demonstrates how to convert a very very
old "procedural, imperative, GOTO" program into a top modern
functional system, Shen.  A GOTO program!  Oh my........

See



Any smart ideas as for how the (set *glob-var* ...)s could be
elegantly eliminated?


yours, Dr A. J. Y.
HELSINKI
Finland

Mark Tarver

unread,
Oct 9, 2015, 4:51:28 PM10/9/15
to Shen
This was great fun!

***** CONTACT *****
TOUCHDOWN AT 20.0 SECONDS.
LANDING VELOCITY= 6 FEET/SEC.
0 UNITS OF FUEL REMAINING.
***** SORRY, BUT YOU BLEW IT!!!!
CONDOLENCES WILL BE SENT TO YOUR NEXT OF KIN.
YOU QUITE LITERALLY BLEW UP, OR, EXPLODED, IT.

A bit hard;  I thought that was a pretty good effort ;)!

Mark

Mark Tarver

unread,
Oct 9, 2015, 5:41:56 PM10/9/15
to Shen

Any smart ideas as for how the (set *glob-var* ...)s could be
elegantly eliminated?


yours, Dr A. J. Y.
HELSINKI
Finland


(define loop-flight
  Time Height Velocity Fuel  
              ->  (do (output "~A      ~A       ~A       ~A~%" Time Height Velocity Fuel)
                      (output "? ")
                      (let Burn (min [(input) Fuel 30])
                           NewVelocity .......
                           FuelRemaining .......
                           NewHeight .......
                           (cases (< NewHeight 0) (contact ...............)
                                  (> FuelRemaining 0) (loop-flight .........................)
                                  true (out-of-fuel ..............................))))) 

as a sketch.  I'll leave you to fill in the blanks.

Mark

Antti Ylikoski

unread,
Oct 9, 2015, 8:27:38 PM10/9/15
to Shen
Try to edit the source code so that the initial amount of fuel is eg. 2000 units.
This makes the flight possibilities more exciting.  You will be able to fly
up and down several times during one landing flight like a yo-yo.

AJY

"Winning the competition is not the point.  Good prizes are."  --Traditional.

fuzzy wozzy

unread,
Oct 10, 2015, 5:40:01 AM10/10/15
to Shen

in a sense, goto was replaced by "c'mere",
instead of going to where the next set of instructions are,
you're asking the instructions to come to where you are, if this makes sense...

only difference is -- at least in this example -- is that,
instead of making sure where you're going-to,
you have to make sure what you're asking to come-to,

strangely though, not understanding the basic nor the shen program to the fullest,
I prefer the basic program, perhaps because the basic program looks more compact and
possibly easier to understand, despite the goto, becuase the whole thing is short enough
(due, perhaps, to less spacing, et cetra, et cetra...) that
goto doesn't really interfere with the understanding of the flow of logic(?), or it could be my
naviete in all things shen, meaning, complete and utter lack of all things when it comes to
shen's sophistication, etc...

or could it be that it was shen's awkward (or lisp or haskell, how about a haskell version, any haskell or ocaml experts out there?)
attempt to translate what amounts to a procedural (not that there's anything wrong with it, as long as it gets the job done
and makes fun happen, really...) program into shen-logic?

whatever may the case be, this to me is a prime if not primal example that shen may be ready for usage in
video game production, via tcl/tk or opengl, just something that could link shen code to graphic animation environment,
how about the "proecessing" langauge that runs on java vm (for crying out loud), and is gaining traction like you wouldn't believe, at least
last I checked...?

I think it is not apropos of nothing, that is to say, it is not too much to say... viva la shen!
Message has been deleted

Mark Tarver

unread,
Oct 11, 2015, 1:44:08 PM10/11/15
to Shen
The problem is that the original QBasic program is written in  a style that would have been thought as old 30 years ago.  A lot of the code would/should have been hived off into procedure calls - not GOTO.   Rewriting it using global assignments doesn't really make it functional.

Mark.

baoloc...@gmail.com

unread,
Oct 19, 2015, 11:06:56 AM10/19/15
to Shen
From a glance, the shen code looks longer(number of words, lines of codes..) than the basic code. I'm assuming the shen code provides more features for the lunar landing game? 

Mark Tarver

unread,
Oct 19, 2015, 11:59:52 AM10/19/15
to Shen
I don't think there any more features.  The program is a transcription of a procedural program using GOTO into a procedural subset of Shen.  It hasn't been written to take any advantage of functional programming.  Rather like buying a sports car and then hitching your horse to it and using it as a carriage.  You'll probably conclude that your old buggy was just as good.  

Mark

Antti Ylikoski

unread,
Nov 10, 2015, 12:02:02 PM11/10/15
to Shen
I interpreted those works by Mark as valuable advice, and created a
fully functional variation of the LUNAR program, also with type
information in functions.

The file is:


I attempted to load it with

> (tc +)
> (load "flunar.shen")

but there were there some issues with the maths-lib library.

It is longer wrt lines and chars than the 1970's BASIC version, but
that is not the point.  The point is that the program is significantly
better software engineering with functional programming, in particular
with the type info there.  It is more instrumental that the software
works, than that it is brief as a source file :))

yours, AJY
HELSINKI
The E.U.

Mark Tarver

unread,
Nov 11, 2015, 1:48:53 PM11/11/15
to Shen
That's cool.  A small point

(define displaydata
  { number --> number --> number --> number --> list }
  T H V F  ->  (let _ (output "~A      ~A       ~A       ~A~%"  T H V F)
                   []))

The type list is actually a parametric type; it expects a type as an argument.  You return something of type (list ...); here (list A) would do.  If you change your program to allow for this you may find it will type check; give it a go.

bw

Mark

Antti Ylikoski

unread,
Nov 11, 2015, 6:46:59 PM11/11/15
to qil...@googlegroups.com
The following happens when attempting to load the flunar.shen, because
of a problem with the maths-lib.shen library:

------------------------------------------------------------

antti@mydebian:~/ShenResearch$ ./Shen

Shen, copyright (C) 2010-2015 Mark Tarver
running under Common Lisp, implementation: SBCL
port 2.0 ported by Mark Tarver


(0-) (tc +)
true

(1+) (load "flunar.shen")


sign : (number --> number)
abs : (number --> number)
floor : (number --> number)
maths.floor-pos : (number --> number)
maths.floor-neg : (number --> number)
maths.floor-h : (number --> (number --> (number --> number)))
ceiling : (number --> number)
trunc : (number --> number)
maths-round0 : (number --> number)
maths.round-down? : (number --> boolean)
int-part : (number --> number)
frac-part : (number --> number)
modf : (number --> (number * number))
maths-round' : (number --> (number --> number))
maths.pow-2 : (number --> (number --> number))
fmod : (number --> (number --> number))
frexp : (number --> (number * number))
maths.frexp-neg : (number --> (number * number))
maths.frexp-pos : (number --> (number * number))
maths.mult-2 : (number --> (number --> (number * number)))
maths.div-2 : (number --> (number --> (number * number)))
ldexp : (number --> (number --> number))
square : (number --> number)
maths.power-pos : (number --> (number --> number))
power : (number --> (number --> number))
maths.type#global : symbol
1.e-15 : number
2.7182818284590455 : number
2.302585092994046 : number
0.6931471805599454 : number
3.141592653589793 : number
1.5707963267948966 : number
0.7853981633974484 : number
6.283185307179586 : number
0.31830988618379075 : number
0.6366197723675814 : number
1.4426950408889634 : number
0.43429448190325187 : number
1.4142135623730951 : number
0.7071067811865476 : number
1.1283791670955126 : number
0.017453292519943295 : number
57.29577951308232 : number
maths.small-enough? : (number --> boolean)
rad->degs : (number --> number)
degs->rad : (number --> number)
dms->degs : ((list number) --> number)
maths.dms->degs-pos : ((list number) --> number)
degs->dms : (number --> (list number))
maths.range-ok? : (number --> boolean)
exp : (number --> number)
maths.exp-large : (number --> number)
maths.exp-h : (number --> number)
maths.exp-sum : (number --> (number --> (number --> (number --> number))))
sinh : (number --> number)
cosh : (number --> number)
tanh : (number --> number)
expt : (number --> (number --> number))
sqrt : (number --> number)
maths.sqrt-scale : (number --> (number --> number))
maths.sqrt-h : (number --> number)
maths.sqrt-iter : (number --> (number --> (number --> number)))
maths.mean : (number --> (number --> number))
log : (number --> number)
maths.log-scale : (number --> (number --> number))
maths.log-h : (number --> number)
maths.log-sum : (number --> (number --> (number --> (number --> number))))
log10 : (number --> number)
log2 : (number --> number)
log' : (number --> (number --> number))
sin : (number --> number)
maths.sin-h : (number --> number)
maths.sin-sum : (number --> (number --> (number --> (number --> (number --> number)))))
cos : (number --> number)
tan : (number --> number)
asin : (number --> number)
maths.asin-h : (number --> number)
maths.asin-sum : (number --> (number --> (number --> (number --> number))))
acos : (number --> number)
atan : (number --> number)
maths.atan-h : (number --> number)
maths.atan-sum : (number --> (number --> (number --> (number --> (number --> number)))))
maths.atan-lt1 : (number --> number)
maths.atan-gt1 : (number --> number)
maths.atan-transf : (number --> number)
atan2 : (number --> (number --> number))
even? : (number --> boolean)
odd? : (number --> boolean)
natural? : (number --> boolean)
positive? : (number --> boolean)
negative? : (number --> boolean)
zero? : (number --> boolean)
maths.rsh : (number --> number)
maths.rsh-h : (number --> (number --> number))
maths./-pos : (number --> (number --> (number * number)))
maths.div-w : (number --> (number --> (number --> (number --> (number * number)))))
maths.pow-2div : (number --> (number --> (number --> number)))
divisible-by? : (number --> (number --> boolean))
type error in rule 3 of prime?

(2+)

......

antti@mydebian:~/ShenResearch$ 
antti@mydebian:~/ShenResearch$

------------------------------------------------------------

yours, AJY
HELSINKI
The E.U.

--
You received this message because you are subscribed to a topic in the Google Groups "Shen" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/qilang/qgxOgugAoVA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to qilang+un...@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at http://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.

Willi Riha

unread,
Nov 12, 2015, 1:19:52 AM11/12/15
to Shen
I don't know why the maths.lib does not load properly, when you have the type checker on!

You loaded it, without any problems, with (tc -). I suspect, that you haven't followed the original instructions regarding
how to load the libraries. There are auxiliary files that need to be loaded (containing various macros etc). This was all documented
a few years ago. In the meantime, I have updated both the maths and the string libraries, but the changes and the documentation have not been posted on the Shen site. I shall ask Mark if a an updated version should be made available. It will still be important to load not just the maths lib, but also any auxiliary files.

When I am programming, I always load all my libraries, before I start. I have developed other libraries, which may (perhaps?) be available with Shen Professional. Really, if you want to do anything constructive, and don't want to reinvent the wheel, you need to resort to existing programs.

The important point is, to follow the instructions. I don'tknow which version of the maths library you are using, but there will be instructions on how to install it.

Willi

 

On Friday, October 9, 2015 at 8:50:34 PM UTC+1, Antti Ylikoski wrote:

Antti Ylikoski

unread,
Nov 12, 2015, 6:31:41 AM11/12/15
to Shen
No -- the function prime? is flawed.

It has been defined as:

------------------------------------------------------------

   
(define prime?
   { number --> boolean }
   2 -> true
   N -> false where (even? N)
   N -> (prime'? N 3 (round(sqrt N))))
   
(define prime'?
   { number --> number --> number --> boolean }
   _ K Limit -> true where (> K Limit)
   N K  _    -> false where (divisible-by? N K)
   N K Limit -> (prime'? N (+ K 2) Limit))


------------------------------------------------------------

First of all, the function (round ...) has not been defined.

Secondly, it should be

------------------------------------------------------------

   
(define prime?
   { number --> boolean }
   2 -> true
   N -> false where (even? N)
   N -> (prime'? N 3 (round (sqrt N)))) \\ !!!! here add a space !!!!
   
(define prime'?
   { number --> number --> number --> boolean }
   _ K Limit -> true where (> K Limit)
   N K  _    -> false where (divisible-by? N K)
   N K Limit -> (prime'? N (+ K 2) Limit))

------------------------------------------------------------

at least I think that the Common LISP reader works like that.

yours, AJY
HELSINKI
The E.U.


Willi Riha

unread,
Nov 12, 2015, 11:26:45 AM11/12/15
to Shen
There is absolutely nothing wrong with the prime? function.
You do not need a bracket, as you suggest. 
However, you are right that round is not defined in math-lib, because it is defined as a macro
in the macro-def file, which you should have loaded. In this file, there is also another macro, needed
in math-lib.

In the meantime, as I hinted at, I have modified the maths library, improving some of the code, and I have also
added the inverse hyperbolic functions (of very little interest, unless you work in applied maths).

I have  included the round macro (and others, like min, max, gcd etc in the file, but there is another macro
which cannot be included, and still needs to be loaded separately. 

Look at the Shen site, where you got the math-lib from and read the readMe file!

Willi

On Friday, October 9, 2015 at 8:50:34 PM UTC+1, Antti Ylikoski wrote:

Willi Riha

unread,
Nov 12, 2015, 11:30:27 AM11/12/15
to Shen
CORRECTION: "You do not need a bracket" should be "You do not need a SPACE!"


On Friday, October 9, 2015 at 8:50:34 PM UTC+1, Antti Ylikoski wrote:

Antti Ylikoski

unread,
Nov 12, 2015, 1:48:38 PM11/12/15
to Shen
Can you help the following problem?

------------------------------------------------------------

antti@mydebian:~/ShenResearch$ ./Shen

Shen, copyright (C) 2010-2015 Mark Tarver
running under Common Lisp, implementation: SBCL
port 2.0 ported by Mark Tarver


(0-) (tc +)
true

(1+) (load "flunar.shen")

recursive-let-list lacks a proper signature.


(2+)

------------------------------------------------------------

The above error happens while loading the file macros-def.shen.

AJY

Mark Tarver

unread,
Nov 12, 2015, 2:18:39 PM11/12/15
to qil...@googlegroups.com
Sounds as if you have failed to attach a type to the function.

Mark

Willi Riha

unread,
Nov 12, 2015, 7:35:50 PM11/12/15
to Shen
the file macro-def needs to be loaded with the type checker off.

Why do you not follow the instructions given in the ReadMe file?
Everything works fine!

By the way, I have looked at your recent (typed!?) version of the lunar landing program.

It will never compile, because a signature {-->}  is illegal (and actually not very meaningful).
In functional programming, every function must return something (some value), even if it is does not make sense.

A function displaying a table of whatever, does not really have a value. Therefore, you have to return something, like a symbol, "done".
It is possible to return an object of type "unit", (as defmacro does), but this is more complicated. "unit", seems to correspond to the C/C++ type "void"

W

On Friday, October 9, 2015 at 8:50:34 PM UTC+1, Antti Ylikoski wrote:

Antti Ylikoski

unread,
Nov 13, 2015, 7:10:21 AM11/13/15
to Shen
Yes; quite so; that error message will come if a function does not
have a type attached to it.

But that was not the problem that occurred.

The definition of the function recursive-let-list in the file
macros-def.shen is as follows:

------------------------------------------------------------

(define recursive-let-list
  _ [] _ W -> W
  N [cons V Vs] Z' W ->
      [let V [nth N Z'] (recursive-let-list (+ N 1) Vs Z' W)])

------------------------------------------------------------

I thought that it would be nice if the author of the function, who
knows precisely how the function works, could write the type
declaration for the function.  The type declaration in question was
missing from the macros-def.shen file that I got from the Shen library
web site, the type declaration needs to be added to that file.

Have a nice day, AJY

Antti Ylikoski

unread,
Nov 13, 2015, 7:10:31 AM11/13/15
to Shen
I wrote my own version of the maths-lib.shen, which version will load
with the type checker on.

The functional lunar simulator is in:


but I have one more beginner's problem.

The flunar.shen will load and work without the type checker, but it
will fail to load with the (tc +), fail in the function loop-flight:


------------------------------------------------------------


(define loop-flight
    { number --> number --> number --> number --> (list A) }
    T H V F
    ->
      (do
         (displaydata T H V F)
         (output "? ")
         (let B (input)
           (if (and (>= B 0)
           (<= B 30)
                    (<= B F))
      (fly-flight B T H V F)
      []))))


------------------------------------------------------------

--- and I cannot discover why.

yours, AJY

(To Will Riha: I apologize: remember that you are dealing with a
beginner!)

Idem

fuzzy wozzy

unread,
Nov 13, 2015, 7:10:36 AM11/13/15
to Shen

how about shor algo in shen, speaking of primes, it's well known enough to be the attraction of those still not sure of shen...

Antti Ylikoski

unread,
Nov 13, 2015, 10:29:06 AM11/13/15
to Shen

Willi Riha

unread,
Nov 13, 2015, 5:19:46 PM11/13/15
to Shen
The function "recursive-let-list" (by Mark) has no type, and therefore must be loaded with (tc -)

W

On Friday, October 9, 2015 at 8:50:34 PM UTC+1, Antti Ylikoski wrote:

fuzzy wozzy

unread,
Nov 14, 2015, 5:41:39 PM11/14/15
to Shen


the fact that no one has been able to (thus far!) prove beyond a shadow of doubt, that is, mathematically,
that the shor algo cannot be done on classical (read: ordinary) computers should give to those who have been
rooting for the "exclusivity" of the domain of quantum computers, a piece of mind or assurance, the fact remains
that it remains to be seen...

Will Strinz

unread,
Nov 16, 2015, 3:38:25 AM11/16/15
to Shen
From my perspective, writing an implementation of the lunar lander game that type checks in is both a cool project and an impressive achievement

However, sorry if I'm derailing this discussion yet further, but I have a layperson's interest in quantum computing complexity theory, and, well, its hard to resist the pull of this.

Its my understanding the fuzzy is basically right, with the caveats that
- Bennet et al have shown that BQP (the complexity class of Shor's algorithm) does not contain NP in a black box setting. So we can say pretty confidently that quantum computers do not magically make exponential computation trivial
- Shor's algorithm does provably run faster than any known "classical" factorization algorithm
- Its very much an open question whether there are any better classical factoring algorithms than the ones we know of now (number sieves), BUT
- Integer factorization has not been proven to be NP complete, and many computer scientists suspect that it is not.
- So, ultimately, whether or not Shor's algorithm offers a speedup over every classical factorization algorithm has only a little bearing on whether quantum computers are "better" than classical computers.

Egregious digression out of the way, I think there is something interesting here for the Shen and its ilk; I've heard people say that good type systems are going to be critical for designing effective languages for programming quantum computers, and Shen's approach to types is intriguingly sui generis.

The current front runners, nascent as they are, seem to hew toward the Haskell / ML /  Hindley Milner style approach (eg Quipper, the latest new hotness)

To the extent that Shen may be able to carve out a space for well-typed programs that aren't rigidly static, I could honestly see it or a future descendant finding a legitimate use in the "workaday" developer's interaction with quantum computers (if that ever comes to pass). For now, Shor's algorithm has been simulated in both C++ and Maple, so there may be more exciting targets for Shen work ;)

PS: if anyone is as baffled by the wiki entry on Shor's Algorithm as I was when I saw it the first time, Scott Aaronson has a nice blog post explaining it a little more intuitively.

Antti Ylikoski

unread,
Nov 18, 2015, 5:03:57 AM11/18/15
to Shen
It has been seen that Shor's algorithm can be executed with ordinary
computers.

But can this be done effectively, to factor large integers efficiently
with the Shor algorithm on classical computers?

Therefore, let us see about that:

Schrodingerian wave functions can be done with methods to handle
numerical complex valued differential equations.  This is starting to
be higher math, but these are to my knowledge standard methods in the
numerical analysis field.  (Is numerical math "higher math"? :)) )

However: The Shor algorithm utilizes the superposition of a rather
large number of quantum states.  (See the Wikipedia algorithm.)

The quantum mechanisms in the quantum computer, can be simultaneously
in a large number of superposition states.

But with a classical computer, we would have to process this large
number of superposition states individually, numerically, in the
virtual memory, serially with the CPU.

Consequence: In all probability, quantum speed up is impossible with a
classical computer.

But: My final answer to the question is, typically of me: Yes and no!

Namely: One exception to the above limitation: Handling a large number
of individual objects (superpositions) could be done efficiently with
parallel processors.  Modern super computers have tens of thousands,
and even more, microprocessor technology processors which can run in
the parallel fashion.

Therefore: Efficient classical computer simulation of the Shor
algorithm is most probably impossible.  But the quantum Shor algorithm
is probably suitable for massively parallel processing on a modern
super computer.


yours, AJY
HELSINKI
The EU

fuzzy wozzy

unread,
Nov 18, 2015, 9:54:17 AM11/18/15
to Shen

I don't know of any easy way of prime factorization of large numbers other than the conventional way
of using division and multiplication in variations, which is neither easy nor efficient, but there's a video
that talks about prime numbers and about 21:25 into it the speaker talks about a lecture from 100 years ago
when people thought that (2^67 - 1) was a prime number, but one professor took an hour of calculation
to find two numbers whose product was equal to (2^67 - 1),

the numbers are large enough that it would take regular computers a good deal more than an hour to find
using conventional way, so either the professor had a shortcut way of calculating it or he was just a genuis
when it came to such calculations.

https://www.youtube.com/watch?v=yhtcJPI6AtY

Antti Ylikoski

unread,
Nov 18, 2015, 10:25:44 AM11/18/15
to Shen
I would compare factoring such an integer, with some mathematical structure, to writing a Python program to make optimal tournament tables for Tandem or Bughouse chess tournaments.  (I have done this.)

A smart mathematician may find all sorts of short cuts and flashes of sudden intuition about the number.

AJY

fuzzy wozzy

unread,
Nov 21, 2015, 7:05:17 AM11/21/15
to Shen

in some limited cases it might be possible to use linear equations,
of course as the complexity grows vectors are preferred (over lists),
for now it would do to apply to a 3 digit number,

Antti Ylikoski

unread,
Nov 21, 2015, 7:47:43 AM11/21/15
to Shen

Pierpaolo Bernardi

unread,
Nov 21, 2015, 11:18:16 AM11/21/15
to qil...@googlegroups.com
On Wed, Nov 18, 2015 at 3:32 PM, fuzzy wozzy <swtch...@gmail.com> wrote:
>
> I don't know of any easy way of prime factorization of large numbers other
> than the conventional way
> of using division and multiplication in variations, which is neither easy
> nor efficient, but there's a video
> that talks about prime numbers and about 21:25 into it the speaker talks
> about a lecture from 100 years ago
> when people thought that (2^67 - 1) was a prime number, but one professor
> took an hour of calculation
> to find two numbers whose product was equal to (2^67 - 1),

I haven't watched the video, but either the lecturer or you
misunderstood the episode.

The professor (Frank Nelson Cole) took one hour to compute 2^67-1, and
then to multiply the two factors that he had found previously, to show
to the audience that he succeded factoring this number. To do this
factorization he worked for several years.

> the numbers are large enough that it would take regular computers a good
> deal more than an hour to find
> using conventional way,

currently, a common laptop using a naive algorithm requires much much
less than an hour (times are in milliseconds):

> (time (scomprimi (sub1 (expt 2 67))))
cpu time: 8375 real time: 8435 gc time: 1255
(193707721 761838257287)

>so either the professor had a shortcut way of
> calculating it or he was just a genuis
> when it came to such calculations.

or he had some 30 years of free time.

fuzzy wozzy

unread,
Nov 21, 2015, 4:40:08 PM11/21/15
to Shen

there is a formula that finds the nth digit of pi, without needing to calculate the preceding digits first,

people are finding all kinds of ways to do the same old calculations in a new and fresh way, if a new way of prime factorization is found, people will only ask what took it so long...

no one runs primality test on 3 or 11 or 13, because it's obvious, but the larger number shouldn't make a difference when a number naturally reveals itself to be a prime number...

sometimes the mind looks for complex solution completely overlooking a simple solution that works just as well...

fuzzy wozzy

unread,
Nov 22, 2015, 10:51:26 AM11/22/15
to Shen

willi once posted that the time for the following was around 18+ secs (at the time it seemed amazing),

(prime? 231483557931140717)

maybe time has improved by now, but 18+ secs is too long, imho,
there's a possibility that the time can be reduced by half, if not more,


fuzzy wozzy

unread,
Nov 22, 2015, 10:51:27 AM11/22/15
to Shen

willi also said, "The performance of "prime?" obviously depends on the size of the integer, N,  to be tested, and hence on the number 
of trial divisions that need to be performed. This number is equal to about (/ (sqrt N) 2)."

it's obvious that this only applies if one were to follow the conventional way, the cumbersome way,
in truth, in 99.9999999% of the cases any prime number can be determined to be a prime number in under a minute or 10 secs
with 100% accuracy, regardless of the size,




Willi Riha

unread,
Nov 22, 2015, 7:21:16 PM11/22/15
to Shen
Regarding the timing of 

     (prime? 231483557931140717)

in Prof Shen it only takes 0.2 secs.

The same with factorising the number:

(2+) (time (factorise 231483557931140717))

run time: 0.20300006866455078 secs
[2976221 77777677777] : (list number)

Still not very good - but a lot better

fuzzy wozzy

unread,
Nov 22, 2015, 11:57:40 PM11/22/15
to Shen

tried out a few numbers on paper,
3 digit numbers worked out ok,
got stuck on a 4 digit number,
starting out small...

fuzzy wozzy

unread,
Nov 23, 2015, 2:29:39 AM11/23/15
to Shen

"Still not very good - but a lot better"

I think it's very good, excellent, in fact,
only thing is the performance lags as the number gets larger, as you've mentioned,
this would be the case for any method used, but with conventional method, it stands out more...

fuzzy wozzy

unread,
Nov 23, 2015, 9:25:56 AM11/23/15
to Shen

 correction...

"any prime number can be determined to be a prime number in under a minute..."

computer always gives more accurate picture of the time than the mind can,
this is still a thought experiment more than anything,
it's not clear at what point during calculation the primality might appear,
that might be something up to the scholars to figure out, who, by the way, were
correct not to declare np-complete on this,
very large numbers probably require more than a minute, maybe even an hour or more,
depending on how large...

fuzzy wozzy

unread,
Nov 23, 2015, 11:04:26 PM11/23/15
to Shen

there was a time when willi chided me for creating remainder and quotient functions from scratch
when they were already available in the math library download, and proceeded to tell me how ineffective
the functions I created from scratch were, which he was absolutely right about, without a single doubt,
(and bless his heart for telling me),

I don't know if it's unique to shen or lisp or what, but it's funny how those "toy" functions that most shenturians would
laugh at for its naviete and everything else that it entails, still manage to play their part in (to me) cool programs
that do what they're supposed to, but not only that, they are not too shy to play "key" roles in projects that are
more than toy programs, as it were, or more than "cool just for being cool's sake" programs,

I guess the moral of the story, if there is one amongst all this rambling, is that, as dr. tarver pointed out in one of his
poignant essays, don't ignore the viewpoints of the newcomers (or beginners), they might have something worthwhile,
(chances are that they really don't, but there is always that 1% or 0.00001% probability that they indeed "do"),
for this dr. tarver is to be commended for his insight and wisdom, imho...

but I digress, so I shan't lest I regress...

so let me close this post by saying, "you shenturians are so lucky, you have no idea..."

fuzzy wozzy

unread,
Nov 24, 2015, 9:22:40 AM11/24/15
to Shen

once the definition of prime number is read and understood, it must be forgotten as much as possible,
if one were to follow the definition to the letter, it becomes a case of chasing the rainbow, beautiful yet elusive...
nothing new under the sun, probably old news to many...

fuzzy wozzy

unread,
Nov 25, 2015, 12:42:23 AM11/25/15
to Shen

at the risk of sounding repetitious, in case anyone hasn't heard the loud and clear message loud and clear enough...

finding prime numbers (and prime number factors, for that matter) has nothing WHATSOEVER with divisions of ANY KIND...

shocking, I know...
but that is the way of mere mortals (which you can continue insisting on following for all anyone might care...),
but as all prime number gods know (and there are plenty, trust me), it is nothing but a popular myth to assuage the
gullible minds of mere motrals with...

take shor algorithm for example... sure it won fields medal, equivalent to nobel prize in mathematics, etc, etc... (yawn),
it took the noble approach of going the most complex way, so complex that it takes $10 million quantum computer to
make it work properly, even then tagged with precaution that the answer is correct with "high probability"...

but take a good look at shor algorithm to see if you can find any "divisions" in any part of the algorithm, you got repeatable patterns,
power functions... quantum fourier transforms... where are the "divisions"? none whatsover, right?

you can spend $10 million for a quantum computer and become prime number god, or take any desktop computer,
be it window-based or apple or what-have-you, throw in shen in the mix, and voila, who'd'a thought?

you are now the prime number god


fuzzy wozzy

unread,
Nov 25, 2015, 12:42:23 AM11/25/15
to Shen

I used to spend (what seemed like) an umpteen amount time wondering how I could improve my division program,
because I had prime numbers I needed to calculate, for God's sake!
but (as it turned out), that was the wrong question to ask...
that was a distraction-galore, and nothing could remove you further from finding the right way than asking such silly
questions, or shall we say, when you put a slight twist to the same question, suddenly you find yourself asking
the right question!
think about this...

fuzzy wozzy

unread,
Nov 26, 2015, 12:57:22 AM11/26/15
to Shen

this is for anyone who might feel that what's been posted here the last few days is too much of a paradigm-shift...
I can relate... I myself was in disbelief over how easy and simple (and yes, simple-minded) it all was,
I would try to be my own naysayer and find any and all ways to disprove but the logic was as solid as 1 + 1 = 2,
and that's something hard to argue with at least from what I can tell (your experience might differ, and that's alright...)

now, it's true that I haven't tried going past the 4 digit number that I originally got stuck with, but that's ok because
I'm not interested to go beyond that at this time, when you know that something works the way your mind envisions it,
then you have no reason/inclination to try to prove anything, you just know what you know...

it's also true that shor algorithm is way beyond my ability to comprehend, I know zero to nothing about finding patterns
or what fourier analysis is (sounds cool though), but I know that it's a monumental achievement of intellectual endeavor,
and deserves all the accolades that it received and will be receiving for generations to come...

but shen also deserves recognition not just for technical acuity and agility, but for its uncanny ability to give
expression to what your mind conceives and wants to express...

I am still reeling from the awesome power of shen to give direct expression to what the mind envisions,
just from what I've experienced in the last few days myself, and I know for a fact that I haven't even seen the tip,
of a tip of an iceberg...

cheers,




Antti Ylikoski

unread,
Nov 26, 2015, 12:33:42 PM11/26/15
to Shen
Signals in electronics are at the time versus the amplitude scale.  The Fourier transform xforms them to the frequency versus the amplitude scale.


Dr AJY
HELSINKI
The E.U.

fuzzy wozzy

unread,
Nov 26, 2015, 7:25:36 PM11/26/15
to Shen

well, a little clarification...

I have no real interest in prime numbers per se,
I always thought of them as interesting but hard to calculate numbers,
I'm not a researcher of prime numbers,
I was using it as an exercise to learn to use shen at its most basic level,
same as when I made the division program with list,
no real interest in it, just thought someone might find it interesting,

now I learned a little more about prime numbers, oh well...
not any theoretical aspect of it, just the calculation part won't be so clumsy is all... big deal (yawn)

I wonder if there's a way to find some theoretical aspect of it to apply to goldberg conjecture (probably not)




fuzzy wozzy

unread,
Jan 7, 2016, 11:36:06 AM1/7/16
to Shen

"It has been seen that Shor's algorithm can be executed with ordinary
computers.

But can this be done effectively, to factor large integers efficiently
with the Shor algorithm on classical computers?"

how large are "large integers"? how fast should the time be to be considered fast?
for example, for a number with x number of digits, the time should take no more than t seconds?

Antti Ylikoski

unread,
Jan 8, 2016, 4:07:43 AM1/8/16
to Shen
A "large integer" would be an integer used in professional mil or state cryptography application, ie. a 1000 or 2000 digit integer.

"Fast" on a discrete (multi-)processor would be, comparable to the performance of the Shor algorithm with a quantum computer.

But I would really like to half jokingly quote one of my mathematics teachers: For a professional mathematician, any finite number is small.

A. J. Y.
HELSINKI
Finland
The EU

fuzzy wozzy

unread,
Jan 8, 2016, 11:09:33 AM1/8/16
to Shen

thank you for the clarification,

rsa algorithm supposedly uses something like 100 digit numbers, this was years ago,
some use other algorithms due to a concern with security of prime numbers,
shen may be able to show that the concern is not unfounded for small enough numbers,




TheSandwichMakr

unread,
Jan 10, 2016, 6:32:24 PM1/10/16
to Shen
Chaging the subject back to the sim for a second; It seems the weird bugs always get me. :(

SEC    FEET      SPEED     FUEL
0      1000       50       150 ? 0
...
9      347.5       95       150 ? 0
10      250.0       100       150 ? 25
11      160.0       80       125 ? 25
12      90.0       60       100 ? 25
13      40.0       40       75 ? 30
14      12.5       15       45 ? 25
15      7.5       -5       20 ? 0
16      10.0       0       20 ? 0
17      7.5       5       20 ? 7
18      3.5       3       13 ? 6
19      1.0       2       7 ? 7
**** OUT OF FUEL ****
20      0.0       0       0
***** CONTACT *****
TOUCHDOWN AT 20.414213562373096 SECONDS.
LANDING VELOCITY= 7.071067811865476 FEET/SEC.
0 UNITS OF FUEL REMAINING.
***** SORRY, BUT YOU BLEW IT!!!!
CONDOLENCES WILL BE SENT TO YOUR NEXT OF KIN.
YOU QUITE LITERALLY BLEW UP, OR, EXPLODED, IT.

Of course, this is due to the original program doing things in horribly wrong ways..., the port is a correct implementation of the wrong program.

fuzzy wozzy

unread,
Jan 12, 2016, 1:19:48 PM1/12/16
to Shen

the (prime?) program above has a special conditional that checks for even numbers,
what about numbers whose last digit is 5?
those are always divisible by 5, aren't they?
if a number is in a list format, it would be easy to check for even numbers,
or multiples of 5, by checking the last digit of a number

Antti Ylikoski

unread,
Jan 12, 2016, 2:19:48 PM1/12/16
to Shen
There are a number of special divisibility rules that can be used like that.

I. e. if the sum of all of the digits of an integer is divisible by 3, then the integer itself is divisible by 3.

If the sum of all digits of an integer is divisible by 9, then that integer is divisible by 9.

All primes are either of the form 6*n + 1, or of the form 6*n - 1, where n is an integer (Can you prove this?)

I actually was some 16 years old when I invented a primes algorithm which I christened the delta sieve, which algorithm is based on this kind of knowledge.  But I never had the time to fully develop and analyse it.

yours, A. J. Y.
FINLAND

fuzzy wozzy

unread,
Jan 12, 2016, 7:16:48 PM1/12/16
to Shen

that would mean that it would take 5 minutes or less to find a 15 million-digit prime number with little effort,
shen may now be the de facto language of choice for prime number researchers.
Reply all
Reply to author
Forward
0 new messages