Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

FFT library and plot

Since FFT was the subject, it seemed fitting to do some Fourier using the FFTW3 library on some audio. Using an example from the net as a starting point was a time saver in one way and not in another. Debugging code is always fun so ... I had used the AT&T voice server to get some audio for the expression "Segmentation fault" as an example and so that was the file to perform FFT with. Step one was to compile and it was necessary to add a few includes for memset and math to resolve some "implicit declaration warns" and it compiled fine. Next was running test and it printed out "Segmentation fault". It didn't seem there was a line to print the input wav file name, but it could have been overlooked. Since my mind is wandering it is an unusual thing that Spock used a Jewish ceremonial gesture as a "Vulcan" symbol of "live long and prosper".

So it took about one second to realize that it was a real SIGSEGV. It took another few minutes to scope out the fact that rplan was "NULL and VOID", which an assert would have been fitting if it was being proffered as something to be used by others, and the gnuplot code was a bit funky and that was fixed in about 30 seconds. Also it was using a "Magic" number to match the file data structure size, even though it is a given in the header of the .wav. Fixed and fixed. The code below shows the two methods of making the FFTW3 plan and the bottom will return NULL with the newer versions. Understandable, changing the spec is not likely to retrofit every code against an interface that is in flux. If the interface allows, somebody will cut that corner anyway so all in all it wasn't too much work to get the image above and left.



rplan = fftw_plan_r2r_1d(n, rdata, idata, FFTW_R2HC, FFTW_ESTIMATE); fftw_execute(rplan);

rplan = fftw_plan_r2r_1d(n, rdata, idata, FFTW_R2HC, FFTW_FORWARD); fftw_execute(rplan);

It does seem fitting that the wav file chosen was "Segmentation fault" by name and content, as if it was an omen of the future. It would have been more fun if SDL sound was included and "Segmentation fault" was spoken right before it crashed.

List like processing

While restructuring the ants program it seemed wise to start with the minimal implementation and determine that every phase was clean in all aspects. By starting with just main and a signal handler for faults it became clear that something was amiss when run with valgrind. It seems that the structures created for signal handling had an uninitialized field that was actually used by the library.


int setup_sigsegv() { sigset_t a; sigemptyset(&a); /* Initialize empty set */ struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_sigaction = signal_segv; action.sa_flags = SA_SIGINFO; action.sa_mask=a;

The above code solves the problem. sigset_t is an array of bits and so has to be handled using different methods than any other type and cannot be type cast to int or long(AFAIK). By using all the facilities of gcc, and the Linux utilities it is possible to have safe code. There has never been a case where the SIGSEGV failed to act on a fault, however this was an accident waiting to happen on top of another accident. The use of valgrind and -Wall helps to identify and correct many common problems that arise due to the sheer complexity of the systems.

The process is being documented in a book done with LaTeX, and I like those latex equations. It gives an opportunity to document the code, create figures that demonstrate the functions and have a ready resource to refresh the understanding of the more complex aspects of mixing scheme, C, and Python within a list-like framework.

It is my hope to extend the structure interface so that when a structure is created, required fields are analyzed and any use without initialization is flagged.

BTW, there are some new open courses up at Harvard, Stanford, Yale and MIT. Lots of fun, probability, programming, tries, hash , physics, matrices, multi-variable math, astronomy, genetics, AI, and a vast array of useful information.

While proof reading the blog post I noticed "memset" and thus that value was in fact cleared to 0 anyway, oh well, tempest in a teapot.

Down the rabbit hole with Alice Infinity


A very good reference for opening and using video streams is starting here and continuing here.

Below is a way to take videos and convert to a different type and size. The picture to the left top is a capture of a single frame of OpenGL in which I loaded from a video file, converted to texture and displayed that on a rotating cube. It was necessary to slow down the video frames using usleep(usec) to synchronize with audio.


ffmpeg -i video320x240.flv -s 512x512 Video512x512.avi

Below is how to use ffmpeg to extract audio from an audio video stream file.

ffmpeg -i video_and_audio.flv -vn -ab 256 just_audio.wav

I can now read video, camera, audio and output video, sound and stills. The nice thing is that it is possible to create video of animated models and recurse those animations within the presentation of the product itself. It is difficult to represent without seeing the video and perhaps I will generate a video for the blog. The problem is upload time, which can be the most time consuming part of the process.

Holodeck OpenGL

Here is the C code that works for YUYV 4:2:2 which is a two pixel code embedded in 4 bytes being Y1UY2V. So Y1 is the gray scale of pixel one and Y2 is the gray scale of pixel2. The second picture video insert is r=g=b=y. After values are converted they must be clamped to the range 0--256. For example r=r&0xff


r =y + 1.370705 * v; g =y - 0.698001 * v - 0.337633 * u; b =y + 1.732446 * u;

I was doing V4L2 today and discovering how to use the interface. It is fairly straight forward and more technically correct than V4L, which makes it more complex to use, but more versatile. I was able to capture video and convert it to RGBA into a texture. The only problem is YUYV format, which is a real twisty little maze. The Y values are luminance and the chroma information is held in the UV parts. The data is chunks of 4 bytes as "Y1 U Y2 V" which are Luminance pixel 1, U, Luminance pixel 2 , and then V. The relationship of UV and Y is not a blog post length subject.

The next step is to create automated audio that is in chunks with a video position designator. In this way I can use espeak and embrola along with models and video and OpenGL to create a continuous stream video that is animated. Blender is nice and so is python, but direct creation of specific paths with "C" is easier at this point, since I have a handle on all the interfaces. It is easy enough to use the library functions to create what ever effect I need and incorporate physic for models and structures.
I can capture video, convert, and record video of complex scenes(or remote telemetry) in near real time.

I am not sure that having "errno" defined when I use V4L2 is such a good idea, as that is a possible variable that I might use in a program. (Well not possibly, already did and had a conflict on compile.) Other than that it seems very well structured and usable.

addr2line Incident (AI)

During the implementation of ".png" files with transparency in an OpenGL program I somewhat inadvertently introduced a SIGSEGV by inappropriately defining the scale of a malloc(size) structure which defines by bytes and I was creating a table of void*, and in a strange way, I was purposely introducing a fault by ignoring my certain assumption that allocating too small a space would lead to an error.

So an error occurred and the only output was a single frivolous error message:


printf("Apoptosis is likely on SIGSEGV!\n");

As a result, I started to debug the fault code to see why it was not working and displaying what I expected. It seems that I had removed the register display and so I uncommented that which gave me some information, but no address information. I added the "-g" option to gcc to include symbols and expected :

sprintf(someString,"addr2line %p -f -e ElfExec",bt[i])
system(someString)
to work.

I had limited references to those in the range 0x400000-0x420000, which had worked in the past.Oddly, when I did "objdump -d ElfExec" it showed that it was now 0x8040000 and above. I have no answer to why the address ranges are changed, but it must be a Linux kernel change that I was not aware of.

I had recompiled with "-g" and still I got no symbols and file name + line came out as ??:0, which implies it could not find the symbols. So the problem was that part of the object files were already up to date and not recompiled, so I used "touch *.c" then "make" and symbols were found.

So I went to the offending line and made malloc(size*8) for the list and it stopped faulting. Then I had to add the following to the texture display to create the appearance of transparency.

glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Assembly Interlude(AI)

dpkg -p linux-image-$(uname -r)
strings exploit
uname -a
cat /proc/kallsyms
man nm
static char ruleTheMachine[]=
"\x57\x50\x65\x48\x8b\x3c\x25\x00\x00\x00\x00"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\xc3";
RET
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x48\xcf";  
IRET
asm volatile("sidt %0" : "=m"(idt));
      "int $0x80\t\n"
      "movl %%esi, %%esp\t\n"
sleep(1);
    asm volatile("int $0xdd\t\n");

ret =  uname(&buf);
printf("System info System Name - %s Release- 
%s Version- %s Machine- 
%s Nodename - %s Domain name - %s\n"
,buf.sysname,buf.release,buf.
version,buf.machine,
buf.nodename,buf.__domainname);

I was looking into an exploit and if you strip away the fluff, it isn't really that tricky. I have done some domination of WindWoes machines and it is not even a challenge. Linux is a little tougher, and it is odd that somebody would not check the over-run on something. Stuff happens, but you would think that if 3 people signed off on a fix that they would check for over runs. It is a an easy thing to do when coding with "C". It is one of those things that always bothered me. Programmers seem to think that there is no physicality. As an assembly programmer first it is odd to copy something without considering what is going to get over-written. The stuff above was the things I noticed about the exploit and sidt, iret, nop slide, allsyms, and then doing an int to the swapped out table.

I never created a wild exploit, but I have tested a few. It is a very complex thing and the edges of infinity can be very sharp and sometimes dangerous.

Being string safe is probably the best thing a person can do in a high level language. I have written into the instruction sequence cache before when assembly coding copy protection, but with an open OS there is no point. I found the code very interesting and I always learn a few things by figuring out how stuff works. "gcc -E" is neat as it allows you to see what the preprocessor thinks it is doing.

Interfacing C and Python using SWIG

In this test I use 4 files to show how this process works.

  1. module.c
  2. swigtest.py
  3. Makefile
  4. myso.i

Makefiles need to have a TAB on the line after the colon and that is odd, but that is just the way it is. The file that does all the work is Makefile which contains this:

all: swig -python myso.i gcc -fpic -c module.c myso_wrap.c -I/usr/include/python2.6/ gcc -shared module.o myso_wrap.o -o _myso.so

The control file for SWIG is myso.i and contains this:

%module myso extern void indicate_link(const char* passedString);

The C code is in module.c and contains this:

#include <stdio.h> void indicate_link(const char* passedString) { printf("STD C interface - passed string = %s.\n", passedString); }

The python file to test this is swigtest.py and contains this:

#!/usr/bin/env python import _myso _myso.indicate_link(' Successful Swig and C and Python test')

The whole process is then done by typing make, and then ./swigtest.py

The methods of interfacing languages varies and this is just one way.

Many other things need to be known and chmod +x swigtest.py is one. Also you may have to sudo apt-get install swig.

The C horse tripped on some C shells

If I type what time is it, my computer does the conversion to computer speak. This is similar to any interpreter who needs to know both languages in order to translate from common usage to Un33ks speak.

This is an example of level one abstraction of using common sentences to interface the system. The code itself is odd, but the result is not. I could name the executable anything, but in this case I called it Dude. So if I type:

Dude what time is it

I will get the time. It is just a game to play with words and shell. I decided that I could just as well make a C program that took a list of sentences and created the shell script as you see it here. The list would simply be an implied if association. This way I could write a list of question and response pairs as they would be typed and generate the shell script without even knowing that the C program was doing the conversion in C l33t speak and the shell was running shell speak. So I could have a file that I edit which contains the definition and it could compile every time I use it. As an extension thought, I could do Google for common questions and see whether it has a hit to see if it makes sense and do a silly AI that just found the sentence and then took links where it existed and parroted one of the responses at random.


if [ $1 == "what" ];then if [ $2 == "time" ]; then if [ $3 == "is" ]; then if [ $4 == "it" ]; then echo UTC is `date -u`;fi;fi else if [ $2 == "day" ]; then if [ $3 == "is" ]; then if [ $4 == "it" ]; then echo "Today is " `date`;fi;fi;fi;fi;fi if [ $1 == "am" ];then if [ $2 == "i" ]; then if [ $3 == "drunk?" ]; then echo Yes you are;fi;fi;fi

This is also how I could make a streaming English converter to a format that the gcc compiler would accept, but mostly it is an idea I had to see how quickly I could take an English sentence and use that as an interface to the system instead of all the symbols that seem to be required when being initiated to Unix. I think it is an unnecessary hurdle in the same way that the use of Latin is an extra layer of abstraction which may make the Doctor sound cool, but a bone is a bone and bones is ossa. I suppose the doctor would never get any patients if he said finger tips instead of the distal phalanges.

It does lose some of the character when done that way, but then a character is an actor and an actor is a deception. I think people like their delusions because it is entertaining and that is fine, I prefer my whiskey without an umbrella.

As far as the third query and response "Am I drunk", the answer is always yes, because a sober person wouldn't ask that question.

The program has some serious practical applications for me when combined with other things like the speech recognizer in video conversion. By using Google to take a string of words and determine how common they are, I can use that information to correct the misinterpreted transcription of MIT lectures. It would be a suggestion that perhaps the sequence was wrong, and depending on whether it was applied as the correction it could be determined if this was an effective method.

I think it is practical application and it could be named anything. So I can type in English and the computer can ask like the old Dr. Sabaitso except it would make sense more often. So I named my file "Dr".

motey@motey-desktop:~$ Dr what time is it UTC is Thu Mar 4 16:16:09 UTC 2010 motey@motey-desktop:~$

Sense, anti-sense, nonsense

template < class T, class Allocator = allocator > class vector;
Mutant nonsense.

That probably doesn't make sense to many people. I understand it because it describes something. The reason I am considering this is because I have developed a language of dimensions and analysis. If a particular object has dimensions(n) which are labeled with names like "x", "red", "texture scaly", "fuzziness", ... and I specify that I would go to dimension position (2,3,4,5,9,1) and rotate 3⇒7 by .1 then it would make perfect sense to me, and the result would be understandable in context, however the context is very complex. In genetics they use the term sense and anti-sense strands ( using 5' and 3' orientation of base sequences ) of DNA as coding and non-coding, which is not always true, but then what is -absolutely true- in an infinite universe.

It seems to me that the structure of knowledge is very much like code dependency or any other dependency. There is an order to the understanding and the complete concept is built upon the understanding of the individual parts. It could be said that a Japanese language statement corresponds exactly to a specific English statement and it becomes semantics. The result is that many things are duplicated in unique context that when decoded becomes the same exact thing expressed by a new path. An example in dimensional space of concepts is go left 2 in dimension 1, go right 2 in dimension 2, then go right 2 in dimension 1. The net effect is to cancel the travel in dimension 1, which then means we have taken a different dimensional context, and arrived at the same concept. This seems to be the basic underlying mechanism and by translating in these symbolic dimensions, it is possible to translate ( hence the name translate and rotate ) the meaning of A and B, though they originate in completely different context.

Here is an example of where complexity extends so far that it confounds the mind to envelop the process, and yet I can easily move about in this n-D space and end up with an answer that makes complete anti-sense to me.

(Unicode: ☺ #263A)

It seems that all understanding can ultimately be integrated in this dependent dimensional space as fairly simple descriptive elements. The net result is that I can define a thinking relationship to extend the concepts and simply present the fact that (unk) solves (unk). The resultant path dimension data can be instantiated in a biological organism to be knowledge that exists at birth. It is beginning to make sense how an ant, dolphin, octopus ... can be born with a certain understanding, that really has nothing to do with our context and the "emotional" ( motional ) understanding is able to be translated from one organism to another or one person or personality. It is very interesting and I expect this to be more clear as I apply it, like any language, that requires std::cout<<"CONTEXT"; to be understood. So it is possible to be born with knowledge that could be quite complex and that would seem to be a better way than spending a life time to find out that Mickey Mouse™ isn't a real a mouse. Of course you couldn't do that as your mind would be filled with holes where the copyright attorneys burned patches of information out , as they own the knowing©. Actually they couldn't do that as they would have to be able to understand how to do it and since they burned the understanding out of everybody, nobody knows how to do "burning minds"© anymore.


I don't know where this came from, but it has something to do with Barbara Streisand in some aspect of her magnetic personality.

The net result of all of this is that I can project in these various dimensions along vectors that describe anything and it relates to how one might do matrix manipulation of OpenGL objects or use linear equation matrix programming in Matlab™ to transform a system. It is reasonable to assume that I can actually project into artistic space a concept that is an image, movie or any extrapolation of human / non-human creativity to produce that which is entertainment. If the process of meta projection is known then the "art" which is generated becomes a process which generates the forms which interest the observer. It does have relationship to the concept of meta code generation. It is said that programming is a human talent and yet I can get my AIs to do it. In this same way I can meta extend it in a complete loop, where the code itself directs the coder. There is a point where coherence of this defines the nature of thought and understanding itself. Organisms are generated from their DNA and then shaped by their experience with the methods at their command. It might be said that by articulating this mechanism in a more effective way that you may have obsoleted the biological form itself. It depends on the context. If the organism I create is an extension of my own understanding and inherently context linked to my being in ways that are not able to be understood without this extension, then it becomes. To some extent I personally find the activity of some people to be utterly transparent and predictable. It remains to be seen what perspective develops if all reason and extension becomes transparent. Another step on the way to infinity. One small step for motey , one giant leap into the unknown.

Many people would underestimate the transparency of their action due to the fact that they have no context or information to understand how it can be so transparent. It is easy to see that a child is transparent in their motives and in that same way the complexity could seem to confound for those who use it to deceive. To a large extent the motive and action methods of many individuals that are driven by greed or self aggrandizement makes them more transparent as they have a simple vector and though they may conceal the path to their desire ( another Hannibal Lecter quote "Desperately random" ) ( or even "Follow the money"), one only needs to wait at the object of their desire and they will arrive. I think it was Anthony Hopkins playing Hannibal Lecter who said:

"And how do we begin to covet, Clarice".

C++ , new opencourse from Australia

Here is a link in the image to the main page and may have some good new things to learn. C is required as a prerequisite. It has a lot of good information presented quickly and coherently. Where my C++ book spends pages and pages on the trivia of programming and examples that children would fall asleep during, this is fast paced and has easy tools to move to topics that are related, move forward and back to skip areas that are very familiar and recap when things don't make sense. All in all it is a very good reference and though I only went through a couple hours of it so far, it is very clear and concise. There is something about just having the spoken word that adds value to the information in its inflection. The professor seems to have a very good grasp of the over arching principles of C++ and object oriented programming , as well as style and focus on creating good usable and reusable code. Linux oriented development.

gimp wavelets and scripts

The image links to a script for gimp that is written in C. The method is quite interesting and shows up on the "Generic->Wavelet decompose" menu once you have run make and make install.. Compile requires at least the dev package:

sudo apt-get install libgimp2.0-dev

While studying guile, clisp, MIT scheme, Haskell, and other scheme / Lisp implementations the underlying guiding principles are becoming clear. It is easier to see how the programs are created for gimp and what the scheme scripts actually do at a machine level.

It seems there are some underlying methods that would be beneficial to be implemented with a gui and meta interface. I also have a better understanding of the underlying library access and it should be possible to implete a complete meta interface that is a windowed OpenGL task that interfaces all of the other graphic modules simultaneously.

This is another example of where a program like Photoshop cannot compete with open source. I can now understand and modify the script to combine Fourier methods, hole filling, and various other tools I have created and published already. It is the factorial combination of action which is the advantage as it is with the serial combination of shell scripts in a manner such as this using pipes:

cat afile | grep whatiwant | wc -l

Interestingly enough while deciding to make a scheme that interprets scheme I encountered this at "null program" implementing wisp which is somebody who seems to be doing just that and I will likely take a look through their code before I jump in and try my concept.

It asked to be fixed - KDE plasmoids

This tutorial on Plasmoids ( a kind of Graboid, from "Tremors" ) at KDE is my subject for the night. I just wanted to use a Python weather widget and it was okay with Centigrade, but when I used Fahrenheit it lied to me, and I heard it whisper FIXME, then it said in a loud commanding voice, "Make me an option for degrees °K". Also I noticed that you can rotate desktop widgets and that is interesting. So here it goes, my first widget repair. The snap of console is just to remind me how they can be run and also I need to find where the widgets are located so I can install a new one.

sudo apt-get install plasma-scriptengine-javascript

So I can run widgets and now I need to make a library function repair for the other one. You will need that package above to do testing along with others perhaps:

plasma-scriptengine-webkit kdebase-runtime kdebase-workspace

`plasmapkg` is in "kdebase-runtime" , Other useful commands are:

plasmapkg -l plasmapkg --help

And for reference, here is a link to valid widget names at KDE. Also here is the link to general tutorial on Plasma which I will start a new post for Python and other language widgets. I downloaded yaWP instead and I am using that source to design another widget. The PyWeather was an odd package and not well received so I will learn in C++ implementation for now and later do Python interface to a widget. It isn't real difficult and mostly it is knowing which functions to use. I will do a post on yaWP in C++

Learning C and some fun

Here is another good teacher at UNSW in Sydney Australia and he manages to make the concepts clear. Because I am self taught I missed many things and it is difficult to integrate some things. When I started programming it was with a little box that you entered hexadecimal codes into and then burned them into a ROM. There were no IDEs, no high level language and definitely no graphics. He must be older than he looks as he speaks about high speed tape systems and that disappeared long ago. I have programmed with punch cards and even panel switches and CMOS logic gates.

Very good stuff and though I really have no fascination for binary logic anymore, it is interesting and he teaches things that transcend implementation.

Hero MTV by UNSW CSE students

This is some real geek art. The semicolon is the thing that got me.

Playing in the streams

Above is what came out of gimp while I was thinking about this and below is an example of looking at the stream ( In Windont ). Linux is naturally open and it makes no difference which program uses the stream, they are all ultimately controlled by me. In Windont each program is from a vendor who wants to take advantage and it is like having evil demons in charge of your data.

Solving a problem for somebody it occurred to me that streams can be a messy thing when programs don't cooperate well. In Windont you can pull things from the stream that you shouldn't or simply dam the stream and that is one of those things that seem odd to me as the environment is not one of cooperation to begin with.

Below is the consequence of me purposely crossing a stream in Linux KDE. I knew what I was doing and if you control the machine you can do anything. The nice thing here is that it had an err ( which I caused on purpose ) and it recovered. That is a good thing for KDE4. I wonder who would actually read my blog and nod "Oh yeah" as I would guess that less than 1% of all people would actually understand what I am discussing. I can read the text below and realize this is the path of invocations and I suppose it could be more verbose and show passed data objects, but I can tell what is going on without that. In this case one thread ( stream ) ceased to exist ( Okay I confess, I killed the thread. ) while another thread still had unfinished business with that threads objects. I'll bet that helps to clear it up?

I bet there is somebody at KDE that would look at that and say in a few seconds, "That is not a real crash". Certainly that must be true as this is not a walk in the park to manage a software interface as complex as KDE or Gnome.

Definition: Windont© is the operating system link that is a pointer to NULL ( or nil ), because the OS it formerly pointed to, is corrupted. The term is not really copyright as it was public domain and common knowledge since the OS it formerly pointed at was first released.

This is an interesting C language course from Sydney Australia UNSW.

Scheme of things

I add a little color to the concept of interfacing using scheme or `guile` or Kawa or a Lisp like language. I personally have an easier time dealing with the code when it is highlighted with color in `kate`. The output is nothing special but it works and that means it is a base case I can extend and test and always revert to see what I screwed up if it fails. Also I wanted to conceptualize CDR and CAR and CONS. It all relates and this does have something to do with trees and matrices and solutions. The sum of the parts is something else and just develops. I suppose it could be something that I could say is "glympisifith"[sic] or some other made up word to reference the complete system, but I don't think people can communicate at that level.


I had said that I would delve deeper into scheme and ".scm" scripting and how it gets integrated in a program and how the scripts actually execute. I have a queue that keeps all the things I must complete and they get pushed and popped all the time. When I am at a dead end to understand something I pop the process and solve the relationships so that I have that dependency satisfied and continue toward the goal. So today I had to pop scheme, guile, Lisp and that category so I could understand how these things relate. I also have to do the same thing with Python+blender along with Python+gimp and ".scm" with many things.

The basic template for this came from GNU here. I didn't find it so clear how all the pieces got assembled and perhaps the person who wrote that tutorial thought they were being very clear, but I did not find it so. This code compiles and runs on my machine. It just makes a box. The point is not to have an elegant application, but to identify the nuance of interfacing (language A) with (language B).


#include <libguile.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> static double x, y; static double direction; static int pendown; /* Simple backend for a Logo like tortoise drawer. */ static const int WIDTH = 10; static const int HEIGHT = 10; static FILE* start_gnuplot () { FILE* output; int pipes[2]; pid_t pid; pipe (pipes); pid = fork (); if (!pid) { dup2 (pipes[0], STDIN_FILENO); execlp ("gnuplot", NULL); return; /* Not reached. */ } output = fdopen (pipes[1], "w"); fprintf (output, "set multiplot\n"); fprintf (output, "set parametric\n"); fprintf (output, "set xrange [-%d:%d]\n", WIDTH, WIDTH); fprintf (output, "set yrange [-%d:%d]\n", HEIGHT, HEIGHT); fprintf (output, "set size ratio -1\n"); fprintf (output, "unset xtics\n"); fprintf (output, "unset ytics\n"); fflush (output); return output; } static FILE* global_output; static void draw_line (FILE* output, double x1, double y1, double x2, double y2) { fprintf (output, "plot [0:1] %f + %f * t, %f + %f * t notitle\n", x1, x2 - x1, y1, y2 - y1); fflush (output); } static void tortoise_reset () { x = y = 0.0; direction = 0.0; pendown = 1; fprintf (global_output, "clear\n"); fflush (global_output); } static void tortoise_pendown () { pendown = 1; } static void tortoise_penup () { pendown = 0; } static void tortoise_turn (double degrees) { direction += M_PI / 180.0 * degrees; } static void tortoise_move (double length) { double newX, newY; newX = x + length * cos (direction); newY = y + length * sin (direction); if (pendown) draw_line (global_output, x, y, newX, newY); x = newX; y = newY; } static void* register_functions (void* data) { return NULL; } int main( int argc, char *argv[]) { int i; global_output = start_gnuplot (); //scm_with_guile (&register_functions, NULL); //scm_shell (argc, argv); tortoise_pendown (); for (i = 1; i <= 4; ++i) { tortoise_move (3.0); tortoise_turn (90.0); } }


# Basic Makefile for the tortoise package. CFLAGS = `guile-config compile` LIBS = `guile-config link` .PHONY: clean build run build: tortoise clean: rm -f tortoise tortoise.o run: tortoise ./tortoise tortoise: tortoise.o gcc $< -o $@ $(LIBS) tortoise.o: tortoise.c gcc -c $< -o $@ $(CFLAGS)

So I get the concept now and `guile` is a bit more understandable in the concept of a universal constructor. I have the framework now and I can fill in easily now from other languages as everything is pretty much the same when you program. I prefer assembly language but it isn't the do all and end all of getting things done, it is just more predictable for me as I am essentially switching gates to get the result I want and in that way I can make it virtually deterministic.

Strange code from the AI

I can't believe that this works, but then it does and as such I learn something about how the pre-processor works.


#include <stdio.h> #define monkey int main(){printf("monkey\n"); return 0;} monkey

gcc monkey.c -o monkey ./monkey

Program output at console.


monkey

I wonder how long it would take somebody to find a fault that was included in the header of some sub header deep into the structure of includes. Obviously it functions as literal GSR ( Global Search and Replace ). In this case it is more like GSW ( Gun Shot Wound ) So I did this:


#define monkey int main(){return 0;} monkey

How to get the intermediate code.


gcc -E monkey.c -o monkey.pre cat monkey.pre

Contents of the file monkey.pre


# 1 "monkey.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "monkey.c" int main(){return 0;}

Turning assertions off , which is something I have seen applied and simply space off, but here it is. By default, ANSI C compilers generate code to check assertions at run-time. Assertion-checking can be turned off by defining the NDEBUG flag by using gcc with the -DNDEBUG flag. To use assertions you would include "assert.h" with code like the following:


#include <stdio.h> #include <stdlib.h> #include <assert.h> int main (){ void *memory; memory =malloc(100); assert(memory != NULL); printf("This prints if allocate succeeds.\n"); free(memory); }

And finally generates this little piece of work.


int main (){ void *memory; memory =malloc(100); ((memory != ((void *)0)) ? (void) (0) : __assert_fail ("memory != ((void *)0)", "monkey.c", 7, __PRETTY_FUNCTION__)); printf("This prints if allocate succeeds.\n"); free(memory); }

I would show the generated assembly code, but that is pretty obvious so I will leave you with this.

The problem with Infinity

-Lecture number five of 6.00 at MIT open courses tells the whole story of why I understand and accept that no digital computer or analog computer will ever make a dent in the computation of the universe or be a device which could do such a strange thing as "upload consciousness". I knew long ago that the math and computers are not up to the task and in fact it hinders the understanding of the universe. I previously had no idea that I could actually implement an infinite math computer and so it was just something to live with. Now that I understand the equation of state of the universe it begins to give insights in how to apply it to create new devices. The logical path is to create a computer which can really model the universe and simulate human neural activity. The universe is an interaction of infinities and it can't be modeled any other way. AFAIK.

Tearing down everything and starting again is what I see as the only way to get an effective end product. If I were perfect and could devise a method that encompassed my goal in a single pass, I would be some valuable commodity, but I can't. I build what I think will do the job, try it out, learn what is needed next and strip it down and reform it until it is complete.

This is how I approach science also. If these guys like Archimedes and Newton and such could come up with a perfect concept cold they would have to be fairly major gods, but they aren't. It isn't easy work, but it is never perfect.

I sympathize with Archimedes, at least in what I understand of him, as he supposedly died trying to get that next thing and this is it, even if you die trying, you have to rip it down and start again and perhaps it will all come together, IDK, that is the future and it can't be predicted.

That lecture also explains some of the rather odd behavior that some programs exhibit. I think Linus was very wise to keep IEEE FP out of the core. Python longs are an interesting thing too. I watched lecture 3 there and saw immediately that no one caught on to the corner case and it screamed at me, "That program will fail intermittently". I see it all the time, that "Black Swan" and the corner case of darkness haunt me as badly as the Werecats.

Dictionary of C

I decided I will create a dictionary for my C metacode generator so that it can analyze success of a program based on its use of words and phrases from a compile dictionary tree. The general concept is to scan files with the extension ".c" on the web and on my local machine and create a dictionary file of words that are most common. I would assume that things like "int" and "char" would be the most common words in the C language and when it was chosing at random an element to implement it can decide from a weighted list of words instead of just random combinations. It is also then possible to make a decision tree that determines how often a specific word follows another specific word or type of word.

These same concepts apply in the analysis of the genetic language of an organism. The problem with genetics is that each new organism is its own language base and though they share words, the language or the end product can be radically different. The overall logic is the same and the technique is used in DNA analysis. I could say that if organism A and B had a specific tRNA in common that it had a degree of similarity, but really, if a Japanese person says RTFM, would you presume that they speak English?

A context array will be the most convoluted aspect of this and it implies that words are common or usable in a specific context such as comments. If the context is between /* and */ the the nature of what you might expect is different. So the division of context will be the second level of analysis and at the moment nothing leaps out as a perfect way to determine if it is the right context detection. I can force it with contrived context, but I want it to devise that itself. So, context is within a ".c", sub context /**/ or {} or line or something else. So I make a framework that attempts to know what the context is first by going through it and making sections and sub-sections to the problem and then a word or sequence can be sorted by context as well as commonality.

I would suspect that a specific person would have a language use profile and that coders have a method use profile that reflects their preference and training.

I discovered some new menu items in `kate` yesterday and they are really nice. I can select a block of code and use the shortcuts "control+d" to make it a comment and "control+shift+d" to uncomment that selected code. I can also use menu 'tools' sub menu item to "pipe to console", which allows me to script in the comments or many other things. I was watching a course in using Python at MIT and it seemed that if they were using `kate` as an IDE, they could more easily demonstrate various personalities of code more quickly as I do this by having several versions of the code in the side bar and switching to them, jumping to console and executing.

In a teaching situation it requires the observer to grasp the concept and so slow application is good, but if you are doing it from a video stream, just pause until it sinks in and continue. The video online courses are really great because I can watch them, fail to grasp the concept and then come back to them in a day or so and then it is more clear. It can be boring to go over and over the lectures, but I use it like an idiot lantern that runs constantly and when I hear something that interests me or is new I perk up and listen. I suppose I am developing a dictionary of opinions and the perspective of a Yale professor, Harvard, MIT and Stanford combine to give me a better idea of what they think object oriented programming is all about. It is a way, the only way?, the final way? I doubt it. Inheritance and complexity can be a real beast and my biggest problem with all code is creeping complexity.

I have been shadowing this course "6.00 Introduction to Computer Science and Programming" in Python with examples and decided to be really compulsive and complete all the exercises including a scrabble where the computer can play itself and mainly I am just trying to be familiar with the nuances of the language so that I can apply it better in other places more efficiently. I have done several Python games already and to some extent I just muddle through and solve things as they arise. Having completed it once through I see it covers some good concepts and adds new aspects to common methods. If I had not completed several of the other courses I would not be able to make sense of some of this as it refers to things like Big O and polynomial time and general code concepts that if you can't place a definition to the words, make it choppy and distracting. It is a very good course and I recommend it to anybody who wants to take a fun slide back through Python or somebody who wants to learn for the first time.

I won't post the Python code I generate so I don't cheat somebody of the experience of doing it themselves because they have too heavy a load. I can't understand these things completely without going through the examples. There is something you learn by doing that can't be duplicated by any amount of explaining. I discovered there is a package called pyscrabble and it implements scrabble, so it is possible to find all this code already completed, but that takes all the learning fun out of the process. Some things cannot be appreciated except in the process and a person who creates the code learns much more than how to program.

openGL compatibility between languages

Something which I just rediscovered today is Rosetta code and I hoped to spend some time looking through that code and today I am looking at the "Knapsack" problem in various languages also as it applies here in a strange way as I need to optimize the speed of the execution of openGL code with a certain number of calls that achieves the same result. This is another weighting that can be used for the automatic code generation and becomes a characteristic of my code.

This is a sample of the Java code that is in LWJGL or Java OpenGL, and as you can see the format is the same and this makes it very easy to create a method on my machine, test it and debug it an then port it to a Java application.

GL11.glPushMatrix(); GL11.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); GL11.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); GL11.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);

Below is the C equivalent of the Java code above and as you can see it simply add the prefix "GL11." and so the process is simple if I maintain some modularity and consider how it will port to Python, Blender, or Java.

glPushMatrix(); glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); glRotatef(view_roty, 0.0f, 1.0f, 0.0f); glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);

And this is some similar code in Lesson 11 of NeHe fame which I converted to Python. It is even more similar and really only loses the ";" at the end of the line and if I rememeber correctly, Python doesn't care if you add that. AFAIK. It does have indents and that is important.

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) glLoadIdentity() glRotatef( lookupdown, 1.0, 0.0 , 0.0 ) glRotatef( sceneroty, 0.0, 1.0 , 0.0 ) glTranslatef( xtrans, ytrans, ztrans )

The first step is to separate the openGL into modular form based on category type with some idea of how it ports between the languages. I suspect that this will give me greater confidence in my code base, as the port can show some flaws in the code that `javac` will tell me or Python will warn. It adds new places where automatic code generation can be certified.

Contributors

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen