<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ponton&#039;s site &#187; Computer science and math</title>
	<atom:link href="http://www.ponton.srednikpe.org/category/comp-and-math/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ponton.srednikpe.org</link>
	<description>blog głównie matematyczno-informatyczny (nie chce mi się pisać o życiu)</description>
	<lastBuildDate>Mon, 18 Jan 2010 22:23:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Matrix chain multiplication: parallel and sequential</title>
		<link>http://www.ponton.srednikpe.org/2009/06/25/matrix-chain-multiplication-parallel-and-sequential/</link>
		<comments>http://www.ponton.srednikpe.org/2009/06/25/matrix-chain-multiplication-parallel-and-sequential/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 19:56:51 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[my code]]></category>
		<category><![CDATA[studia]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=259</guid>
		<description><![CDATA[Yep, that&#8217;s the project that uses threads. Nothing more is worth to add &#8212; the problem is well-known, as well as the algorithm. Source: http://www.srednikpe.org/src/matrix/]]></description>
			<content:encoded><![CDATA[<p>Yep, that&#8217;s the project that uses threads. Nothing more is worth to add &#8212; the problem is well-known, as well as the algorithm.</p>
<p>Source: <a href="http://www.srednikpe.org/src/matrix/">http://www.srednikpe.org/src/matrix/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/06/25/matrix-chain-multiplication-parallel-and-sequential/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ hidden feature</title>
		<link>http://www.ponton.srednikpe.org/2009/06/22/c-hidden-feature/</link>
		<comments>http://www.ponton.srednikpe.org/2009/06/22/c-hidden-feature/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 18:32:43 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[cpp]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=253</guid>
		<description><![CDATA[This is one I didn&#8217;t know. Conditional expressions in C++ can be lvalue: &#40;a == 0 ? a : b&#41; = 42; More hidden features: http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/]]></description>
			<content:encoded><![CDATA[<p>This is one I didn&#8217;t know. Conditional expressions in C++ can be lvalue:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #008000;">&#40;</span>a <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">?</span> a <span style="color: #008080;">:</span> b<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">42</span><span style="color: #008080;">;</span></pre></div></div>

<p>More hidden features: <a href="http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/">http://beerpla.net/2009/06/21/hidden-features-of-perl-php-javascript-c-c-c-java-ruby-python-and-others-collection-of-incredibly-useful-lists/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/06/22/c-hidden-feature/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>boost::thread and std::list</title>
		<link>http://www.ponton.srednikpe.org/2009/06/22/boostthread-and-stdlist/</link>
		<comments>http://www.ponton.srednikpe.org/2009/06/22/boostthread-and-stdlist/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 01:28:49 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[my code]]></category>
		<category><![CDATA[stl]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=243</guid>
		<description><![CDATA[I had to create many threads in C++. Of course I didn&#8217;t want to use pthread, because it&#8217;s ugly C. I chose boost::thread instead. Then I needed some container to keep all these threads. Arrays were out of the question for the same reason as pthread. I could use boost:array but stl::list was easier. The [...]]]></description>
			<content:encoded><![CDATA[<p>I had to create many threads in C++. Of course I didn&#8217;t want to use pthread, because it&#8217;s ugly C. I chose boost::thread instead. Then I needed some container to keep all these threads. Arrays were out of the question for the same reason as pthread. I could use boost:array but stl::list was easier.</p>
<p>The problem was&#8212;how to keep this thread objects? I couldn&#8217;t use std::list&lt;boost::thread&gt; nor std::list&lt;boost::thread &amp;&gt; because threads cannot be copied. I had to dynamically create the object in order to prevent the destruction after the scope. But for some reason I got compiler error while trying std::list&lt; std::auto_ptr&lt;boost::thread&gt; &gt; in the line where I pushed_back newly created threads.</p>
<p>The cause of the error was that the argument of std::list::push_back() was a constant reference. And while assinging one auto_ptr to another, the first one is getting call release() method, but it can&#8217;t since the reference is constant and release() change the state of the object.</p>
<p>To solve this problem one can use boost::shared_ptr.</p>
<p>Example:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;list&gt;</span>
<span style="color: #339900;">#include &lt;boost/thread.hpp&gt;</span>
<span style="color: #339900;">#include &lt;boost/date_time.hpp&gt;</span>
<span style="color: #339900;">#include &lt;boost/smart_ptr.hpp&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> std<span style="color: #008080;">::</span><span style="color: #007788;">list</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">struct</span> foo
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">void</span> operator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> id<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;starting thread &quot;</span> <span style="color: #000080;">&lt;&lt;</span> id <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #008080;">;</span>
		boost<span style="color: #008080;">::</span><span style="color: #007788;">this_thread</span><span style="color: #008080;">::</span><span style="color: #007788;">sleep</span><span style="color: #008000;">&#40;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">posix_time</span><span style="color: #008080;">::</span><span style="color: #007788;">seconds</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;ending thread &quot;</span> <span style="color: #000080;">&lt;&lt;</span> id <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">typedef</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">shared_ptr</span><span style="color: #000080;">&lt;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">thread</span><span style="color: #000080;">&gt;</span> thread_ptr<span style="color: #008080;">;</span>
	list<span style="color: #000080;">&lt;</span>thread_ptr<span style="color: #000080;">&gt;</span> thread<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;creating threads<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">10</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		thread.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">shared_ptr</span><span style="color: #000080;">&lt;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">thread</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">thread</span><span style="color: #008000;">&#40;</span>foo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;after creation, now joining them<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>list<span style="color: #000080;">&lt;</span>thread_ptr<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> it <span style="color: #000080;">=</span> thread.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> it <span style="color: #000040;">!</span><span style="color: #000080;">=</span> thread.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>it<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>join<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;ending program&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>And the result:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tomek<span style="color: #000000; font-weight: bold;">@</span>notlob:~<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">g++</span> <span style="color: #660033;">-o</span> threads threads.cpp <span style="color: #660033;">-O2</span> <span style="color: #660033;">-Wall</span> -lboost_thread-mt
tomek<span style="color: #000000; font-weight: bold;">@</span>notlob:~<span style="color: #000000; font-weight: bold;">%</span> .<span style="color: #000000; font-weight: bold;">/</span>threads
creating threads
starting thread <span style="color: #000000;">1</span>
starting thread <span style="color: #000000;">0</span>
starting thread <span style="color: #000000;">2</span>
starting thread <span style="color: #000000;">3</span>
starting thread starting thread <span style="color: #000000;">4</span>
<span style="color: #000000;">5</span>
starting thread <span style="color: #000000;">6</span>
starting thread <span style="color: #000000;">7</span>
starting thread <span style="color: #000000;">8</span>
starting thread <span style="color: #000000;">9</span>
after creation, now joining them
ending thread <span style="color: #000000;">1</span>
ending thread <span style="color: #000000;">3</span>
ending thread <span style="color: #000000;">5</span>
ending thread <span style="color: #000000;">4</span>
ending thread <span style="color: #000000;">0</span>
ending thread <span style="color: #000000;">2</span>
ending thread <span style="color: #000000;">6</span>
ending thread <span style="color: #000000;">8</span>
ending thread <span style="color: #000000;">7</span>
ending thread <span style="color: #000000;">9</span>
ending program</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/06/22/boostthread-and-stdlist/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How not to name variables</title>
		<link>http://www.ponton.srednikpe.org/2009/06/13/how-not-to-name-variables/</link>
		<comments>http://www.ponton.srednikpe.org/2009/06/13/how-not-to-name-variables/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 18:00:31 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Real life]]></category>
		<category><![CDATA[idiot]]></category>
		<category><![CDATA[narzekanie]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ur doin it wrong]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/2009/06/13/how-not-to-name-variables/</guid>
		<description><![CDATA[This is is a Python line of code which I found in my project I work with two colleagues: for mid, mda, xmht, xmat, mhs, mas, mehs, meas, mphs, mpas, mrou in q: # .... No comments.]]></description>
			<content:encoded><![CDATA[<p>This is is a Python line of code which I found in my project I work with two colleagues:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">for</span> mid, mda, xmht, xmat, mhs, mas, mehs, meas, mphs, mpas, mrou <span style="color: #ff7700;font-weight:bold;">in</span> q:
    <span style="color: #808080; font-style: italic;"># ....</span></pre></div></div>

<p>No comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/06/13/how-not-to-name-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Semantyka gier</title>
		<link>http://www.ponton.srednikpe.org/2009/02/09/semantyka-gier/</link>
		<comments>http://www.ponton.srednikpe.org/2009/02/09/semantyka-gier/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 15:13:50 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[Polskie]]></category>
		<category><![CDATA[beamer]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[semantyka]]></category>
		<category><![CDATA[semantyka gier]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=198</guid>
		<description><![CDATA[Krótki wstęp do semantyki gier, który przygotowałem w ramach projektu końcowego z Semantyk Języków Programowania. prezentacja, notatki Update: notatki pozostałych studentów.]]></description>
			<content:encoded><![CDATA[<p>Krótki wstęp do semantyki gier, który przygotowałem w ramach projektu końcowego z Semantyk Języków Programowania.</p>
<p><a href="http://www.srednikpe.org/tmp/semantyka_gier.pdf">prezentacja</a>, <a href="http://www.srednikpe.org/tmp/sg_notatki.pdf">notatki</a></p>
<p>Update: <a href="http://www.ii.uni.wroc.pl/~dabi/Teaching/Semantyka08/prezentacje.html">notatki pozostałych studentów</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/02/09/semantyka-gier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programowanie literackie</title>
		<link>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/</link>
		<comments>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 01:57:52 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[Polskie]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[tex]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=183</guid>
		<description><![CDATA[Ostatnio miałem ponowną styczność z TeX-em, tym razem konkretnie z Beamerem (całkiem fajne narzędzie do tworzenia ładnych i profesjonalnych prezentacji; być może wrzucę tę, którą zrobiłem na zajęcia). Jest to jeden z programów, które są owiane dla mnie lekką tajemnicą&#8230; Już sam fakt że został napisany przez legendarnego Donalda Knutha, powoduje bojaźn i trwogę podczas [...]]]></description>
			<content:encoded><![CDATA[<p>Ostatnio miałem ponowną styczność z TeX-em, tym razem konkretnie z Beamerem (całkiem fajne narzędzie do tworzenia ładnych i profesjonalnych prezentacji; być może wrzucę tę, którą zrobiłem na zajęcia). Jest to jeden z programów, które są owiane dla mnie lekką tajemnicą&#8230; Już sam fakt że został napisany przez legendarnego Donalda Knutha, powoduje bojaźn i trwogę podczas używania. No dobra, przesadzam, ale TeX to program wyjątkowy. Nie dlatego, że jest bezbłędny (ma już ze 30 lat chyba, a ostatni błąd wykryto w nim kilkanaście lat temu), ale dlatego, że jest napisany&#8230; literacko.</p>
<p>Donald Knuth napisał książkę-program pod tytułem <em>TeX: The Program</em> (ISBN: 0201134373). Następnie (a może uprzednio?) napisał narzędzie, które nazwał WEB. WEB pozwalał mu automatycznie skonwertować książkę-program do poprawnego programu w Pascalu (w tamtych czasach był to bardzo popularny język), który po skompilowaniu robił to, co opisano w książkoprogramie. Oprócz tego, pozwalał też wygenerować&#8230; książkę. Z nagłówkami, sekcjami, stronami &#8212; ot, PDF lub PostScript, nadający się do wydrukowania.</p>
<p>Książkoprogram to tak naprawdę dokumentacja i kod w jednym. Programista pisze na przemian kod i tekst. Może przy pisaniu kodu korzystać ze wszystkich dobrodziejstw TeX-a do opisywania swojego kodu, tworzyć odnośniki do innych fragmentów kodu, etc. Lepiej to zobaczyć na przykładzie: <a href="http://srednikpe.org/src/kwadrat/kwadrat.w">kwadrat.w</a>. Użyłem wesji WEB dla C/C++, która nazywa się <a title="CWEB" href="http://www-cs-faculty.stanford.edu/~knuth/cweb.html">CWEB</a>. Aby otrzymać program C, wystarczy polecnie:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ctangle kwadrat
This is CTANGLE, Version <span style="color: #000000;">3.64</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Writing the output <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>kwadrat.c<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Done.
<span style="color: #7a0874; font-weight: bold;">&#40;</span>No errors were found.<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-o</span> kwadrat kwadrat.c <span style="color: #660033;">-lm</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>kwadrat
Podaj a: <span style="color: #000000;">1</span>
Podaj b: <span style="color: #000000;">10</span>
Podaj c: <span style="color: #000000;">5</span>
x = -<span style="color: #000000;">9.472136</span>
x = -<span style="color: #000000;">0.527864</span></pre></div></div>

<p>Aby otrzymać dokument TeX-a, należy napisać:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cweave kwadrat
This is CWEAVE, Version <span style="color: #000000;">3.64</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Writing the output file...
Writing the index...
Done.
<span style="color: #7a0874; font-weight: bold;">&#40;</span>No errors were found.<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ pdftex kwadrat.tex
This is pdfTeXk, Version <span style="color: #000000;">3.141592</span>-1.40.3 <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>...<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Output written on kwadrat.pdf <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span> pages, <span style="color: #000000;">63651</span> bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Transcript written on kwadrat.log.</pre></div></div>

<p>Oto wygenerowane pliki: <a href="http://srednikpe.org/src/kwadrat/kwadrat.tex">kwadrat.tex</a>, <a href="http://srednikpe.org/src/kwadrat/kwadrat.pdf">kwadrat.pdf</a> i <a href="http://srednikpe.org/src/kwadrat/kwadrat.c">kwadrat.c</a>. Niestety nie wiem jak zmusić czystego TeX-a do poprawnego czytania UTF-8, dlatego w PDF-ie nie ma polskich liter.</p>
<p>Szczerze mówiąc nie mam zdania na temat <em>literate programming</em>. Jeśli ktoś lubi tak pisać, to proszę bardzo &#8212; całkiem przyjemnie się czyta taki dokument. Jednak ja nie lubię się rozpisywać nad kodem, dla mnie sam kod (z komentarzami) stanowi wystarczającą dokumentację. ;)</p>
<p>Warto jeszcze dodać, że wsparcie dla <em>literate programming</em> jest zaimplementowane w Haskellu. Ale to już lepiej poczytać na <a title="Literate programming in Haskell" href="http://www.haskell.org/haskellwiki/Literate_programming">Haskell Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Program verification conditions</title>
		<link>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/</link>
		<comments>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 00:39:01 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=159</guid>
		<description><![CDATA[Yay, another parser in Haskell! That was a Haskell week, but I&#8217;m glad I had an opportunity to recall this beautiful full-of-math language. This program reads an annotated program &#8212; a program with assertions. Assertions are just logic formulas. We use them to describe the program state between instructions, ie. variable x is equal to [...]]]></description>
			<content:encoded><![CDATA[<p>Yay, another parser in Haskell! That was a Haskell week, but I&#8217;m glad I had an opportunity to recall this beautiful full-of-math language.</p>
<p>This program reads an annotated program &#8212; a program with assertions. Assertions are just logic formulas. We use them to describe the program state between instructions, ie. variable x is equal to variable y squared. But assertions cannot be random, they must be derived from Hoare&#8217;s logic axioms and rules (which base on the formal semantic of the language). How do we know if there is an derivation of a program?</p>
<p>Here verification condicitions come. They are logic formulas too, but generated from annotated program. If all of them are true, then the program is derivable. More information here: <a href="http://www.macs.hw.ac.uk/~air/hic-hisd/">http://www.macs.hw.ac.uk/~air/hic-hisd/</a> and <a href="http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html">http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html</a>. The whole point is about formal verification of programs. Nowadays compiler can tell only whether given program has a syntax or type error. It doesn&#8217;t know anything about how this program should work and can&#8217;t  say something like: &#8220;This program certainly does not multiply matrices.&#8221;. Assertions are some way to tell the programmer&#8217;s intentions to the compiler: &#8220;This is my piece of code and it should multiply two matrices&#8221;, and thus, by generating verification conditions and using automated theorem proving it could say: &#8220;It does.&#8221;.</p>
<p>So after a boring digression&#8230; this program reads an annotated program in a simple imperative language and generates verification conditions. That&#8217;s all.</p>
<p>All files are here: <a href="http://srednikpe.org/src/vc/">http://srednikpe.org/src/vc/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reverse Polish notation calculator in Haskell</title>
		<link>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/</link>
		<comments>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 00:02:51 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=155</guid>
		<description><![CDATA[Just a few lines of code, written when I was slightly bored. module Main where &#160; data Token = Plus &#124; Minus &#124; Divide &#124; Times &#124; Num Integer &#160; rpnEval :: &#91;Token&#93; -&#62; Integer rpnEval = rpnEval' &#91;&#93; where rpnEval' &#40;i:s&#41; &#91;&#93; = i rpnEval' s &#40;&#40;Num i&#41;:t&#41; = rpnEval' &#40;i:s&#41; t rpnEval' &#40;a:b:s&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Just a few lines of code, written when I was slightly bored.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> Token <span style="color: #339933; font-weight: bold;">=</span> Plus <span style="color: #339933; font-weight: bold;">|</span> Minus <span style="color: #339933; font-weight: bold;">|</span> Divide <span style="color: #339933; font-weight: bold;">|</span> Times <span style="color: #339933; font-weight: bold;">|</span> <span style="color: #cccc00; font-weight: bold;">Num</span> <span style="color: #cccc00; font-weight: bold;">Integer</span>
&nbsp;
rpnEval <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>Token<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Integer</span>
rpnEval <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #06c; font-weight: bold;">where</span>
		rpnEval' <span style="color: green;">&#40;</span>i:s<span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> i
		rpnEval' s <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> i<span style="color: green;">&#41;</span>:t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#40;</span>i:s<span style="color: green;">&#41;</span> t
		rpnEval' <span style="color: green;">&#40;</span>a:b:s<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>op:t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>evalOp op a b<span style="color: green;">&#41;</span>:s<span style="color: green;">&#41;</span> t
&nbsp;
		evalOp Plus <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">+</span><span style="color: green;">&#41;</span>
		evalOp Minus <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">-</span><span style="color: green;">&#41;</span>
		evalOp Times <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">*</span><span style="color: green;">&#41;</span>
		evalOp Divide <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">div</span>
&nbsp;
toToken <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Token
toToken <span style="background-color: #3cb371;">&quot;+&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Plus
toToken <span style="background-color: #3cb371;">&quot;-&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Minus
toToken <span style="background-color: #3cb371;">&quot;*&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Times
toToken <span style="background-color: #3cb371;">&quot;/&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Divide
toToken s <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #cccc00; font-weight: bold;">Num</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> s<span style="color: green;">&#41;</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
	l <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">getContents</span>
	<span style="font-weight: bold;">mapM</span> <span style="font-weight: bold;">print</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>rpnEval <span style="color: #339933; font-weight: bold;">.</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> toToken<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">words</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">lines</span> l<span style="color: green;">&#41;</span></pre></div></div>

<p>Update: See comments for better solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Kości</title>
		<link>http://www.ponton.srednikpe.org/2008/08/30/kosci/</link>
		<comments>http://www.ponton.srednikpe.org/2008/08/30/kosci/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 00:18:12 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[Polskie]]></category>
		<category><![CDATA[my code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=104</guid>
		<description><![CDATA[Nie mieliśmy kości na sesję, to trzeba było coś napisać. NWOD-owy rzucacz kośćmi w Pythonie: #!/usr/bin/python &#160; import time import random import sys &#160; # argumenty: ile_scian = int&#40;sys.argv&#91;1&#93;&#41; # ilusciennymi koscmi rzucamy sukces = int&#40;sys.argv&#91;2&#93;&#41; # od ilu oczek jest sukces ile_rzutow = int&#40;sys.argv&#91;3&#93;&#41; # ile razy rzucamy &#160; def kostka&#40;sciany&#41;: rzut = random.randint&#40;1, [...]]]></description>
			<content:encoded><![CDATA[<p>Nie mieliśmy kości na sesję, to trzeba było coś napisać. NWOD-owy rzucacz kośćmi w Pythonie:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># argumenty: </span>
ile_scian = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>    <span style="color: #808080; font-style: italic;"># ilusciennymi koscmi rzucamy</span>
sukces = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>       <span style="color: #808080; font-style: italic;"># od ilu oczek jest sukces</span>
ile_rzutow = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>   <span style="color: #808080; font-style: italic;"># ile razy rzucamy</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> kostka<span style="color: black;">&#40;</span>sciany<span style="color: black;">&#41;</span>:
    rzut = <span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, sciany<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> rzut
    <span style="color: #ff7700;font-weight:bold;">return</span> rzut
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'------------------------------'</span>
&nbsp;
<span style="color: #dc143c;">random</span>.<span style="color: black;">seed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
sukcesy = <span style="color: #ff4500;">0</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, ile_rzutow<span style="color: black;">&#41;</span>:
    rzut = kostka<span style="color: black;">&#40;</span>ile_scian<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> rzut <span style="color: #66cc66;">&gt;</span>= sukces:
        sukcesy += <span style="color: #ff4500;">1</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> rzut == ile_scian:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Przerzut!'</span>
&nbsp;
        rzut = kostka<span style="color: black;">&#40;</span>ile_scian<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> rzut <span style="color: #66cc66;">&gt;</span>= sukces:
            sukcesy += <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Sukcesy: &quot;</span>, sukcesy</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/08/30/kosci/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>gdb</title>
		<link>http://www.ponton.srednikpe.org/2008/08/30/gdb/</link>
		<comments>http://www.ponton.srednikpe.org/2008/08/30/gdb/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 22:54:40 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Polskie]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=52</guid>
		<description><![CDATA[Debuggowanie potrafi niemal wykładniczo skrócić czas szukania błędów w programie, więc warto nauczyć się sprawnie obsługiwać debugger. Dotychczas GNU Debugger był dla mnie czarną magią, a wzorem &#8212; ten  z Visual Studio. Tylko gdzieś słyszałem/czytałem, że gdb ma takie same możliwości, ale nie dane mi było się o tym przekonać. Niedawno musiałem się nauczyć jego [...]]]></description>
			<content:encoded><![CDATA[<p>Debuggowanie potrafi niemal wykładniczo skrócić czas szukania błędów w programie, więc warto nauczyć się sprawnie obsługiwać debugger. Dotychczas GNU Debugger był dla mnie czarną magią, a wzorem &#8212; ten  z Visual Studio. Tylko gdzieś słyszałem/czytałem, że gdb ma takie same możliwości, ale nie dane mi było się o tym przekonać. Niedawno musiałem się nauczyć jego obsługi, dlatego napiszę sobie ściągawkę (nie, żeby z niej korzystać, ale żeby utrwalić).</p>
<p><strong>Zanim zaczniesz</strong></p>
<p>Musisz najpierw skompilować program z informacjami dla gdb. Robi opcja -g dla gcc.</p>
<p><strong>Komendy</strong></p>
<p>Zamiast miłego interfejsu graficznego, jest miły wiersz poleceń (co dla programisty jest wygodniejsze, bo nie musi odrywać rąk od klawiatury :&gt;), w którym wpisujesz polecenia. Nie musisz podawać jej pełnej nazwy, wystarczy jednoznaczny początek (najczęstsze polecenia mają jedno/dwuliterowe synonimy). Działa dopełnienie tabulatorem! W razie czego: <strong>help komenda</strong>.</p>
<p><strong>Start</strong></p>
<p><strong></strong>Pierwszy paremtr to nazwa pliku wynikowego programu. Drugim może być numer procesu tego programu, jeśli chcesz zacząć debuggować już działający program.</p>
<p>Przydatne komendy:</p>
<ul>
<li><strong>run [argumenty]</strong> &#8211;  uruchamia program z podanymi (opcjonalnymi) argumentami</li>
<li><strong>continue</strong> &#8211; jeśli program jest zatrzymany, wznawia jego działanie</li>
<li><strong>finish</strong> &#8211; program się wykonuje aż do napotkania &#8220;return&#8221;; innymi słowy program działa aż do końca aktualnej ramki stosu</li>
</ul>
<p><strong>Stop</strong></p>
<p>Żeby się gdzieś zatrzymać, trzeba ustawić breakpointy:</p>
<ul>
<li><strong>breakpoint funkcja</strong> &#8211; ustala breakpoint na początek funkcji</li>
<li><strong>breakpoint [plik:]linia</strong> &#8211; ustala breakpoint na określoną linię pliku</li>
<li><strong>info breakpoints</strong> &#8211; wypisuje utawione breakpointy</li>
<li><strong>delete n</strong> &#8211; usuwa n-ty breakpoint</li>
<li><strong>condition n cond</strong> &#8211; ustala warunek dla n-tego breakpointa (program zatrzyma się na nim, jeśli zostanie spełniony warunek cond)</li>
<li><strong>^C </strong>- czyli przerwanie z klawiatury, również zatrzymuje działający program i oddaje kontrolę gdb</li>
</ul>
<p><strong>Co się dzieje?</strong></p>
<p>Kilka przydatnych komend, aby zorientować się, co się aktualnie dzieje:</p>
<ul>
<li><strong>list</strong> &#8211; listing kodu (10 linii obecnego kontekstu, podana nazwa funkcji, numer linii, etc.)</li>
<li><strong>frame</strong> &#8211; aktualna ramka stosu oraz aktualna instrukcja</li>
<li><strong>backtrace</strong> &#8211; ślad stosu</li>
<li><strong>print x</strong> &#8211; wypisanie wartości x (to może być dowolne wyrażenie, razem ze zmiennymi w programie)</li>
</ul>
<p><strong>Tropimy</strong></p>
<p>To, co najważniejsze, czyli śledzimy program krok po kroku:</p>
<ul>
<li><strong>next</strong> &#8211; następna instrukcja (lub n instrukcji), bez wchodzenia wgłąb procedur</li>
<li><strong>step</strong> &#8211; j/w, ale z wchodzeniem wgłąb</li>
</ul>
<p><strong>Psujemy</strong></p>
<p>Można przetestować kilka rzeczy w trakcie trwania programu:</p>
<ul>
<li><strong>set x wartość</strong> &#8211; ustawiamy zmiennej x wartość</li>
<li><strong>call f(x)</strong> &#8211; wywołujemy funkcję f z argumentami (w tym wypadku tylko x)</li>
</ul>
<p><strong>Format zapisu zmiennych, funkcji i adresów.</strong></p>
<p>Czasem chcemy się odwołać do zmiennej z jakiegoś innego zakresu albo funkcji składowej, wtedy piszemy zakres::x, jeśli np. zakres jest klasą, a x jej metodą/polem, albo zakres jest funkcją, a x jej zmienną lokalną. Odwołanie do konkretnej linii ma składnię plik:linia, np. test.c:244. Adres zapisujemy z gwiazdką na początku, np. *0&#215;000000.</p>
<p>A na koniec: <strong>quit</strong>. I tyle. To było zaledwie 1/5 możliwości gdb, mimo to spokojnie wystarczy do efektywnego debuggowania. Chociaż dziesiątki printfów mają swój urok. ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/08/30/gdb/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
