<?xml version="1.0" encoding="UTF-8" ?>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns="http://purl.org/rss/1.0/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">

  <channel rdf:about="https://chouprogramming.blog-sim.com/RSS/100/">
    <title>超プログラミング</title>
    <link>https://chouprogramming.blog-sim.com/</link>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="https://chouprogramming.blog-sim.com/RSS/" />
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" />
    <description>数多のプログラミングを極めようとせんとする漢のブログ</description>
    <dc:language>ja</dc:language>
    <dc:date>2015-01-18T06:43:50+09:00</dc:date>
    <items>
    <rdf:Seq>
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/daily/2015-01-17-%E3%80%8C%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB%E3%82%B0%E3%83%A9%E3%82%B9%E3%80%8D%E5%80%8B%E4%BA%BA%E5%90%91%E3%81%91%E8%B2%A9%E5%A3%B2%E4%B8%AD%E6%AD%A2" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/manga/2015-01-12-%E5%AF%84%E7%94%9F%E7%8D%A3" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/manga/2015-01-12-%E3%83%94%E3%83%B3%E3%83%9D%E3%83%B3" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/daily/2015-01-11" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/lisp/%E5%86%8D%E5%B8%B0%E9%96%A2%E6%95%B0" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/lisp/%E7%9C%9F%E5%81%BD%E3%81%AE%E5%88%A4%E5%AE%9A%E3%82%92%E3%81%97%E3%82%88%E3%81%86" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%AE-hello-%20world-" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/lisp/%E9%96%A2%E6%95%B0%E3%81%AE%E5%AE%9A%E7%BE%A9" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%AE%E5%9F%BA%E6%9C%AC" />
      <rdf:li rdf:resource="https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%A8%E3%81%AF%E3%81%AA%E3%82%93%E3%81%9E%EF%BC%9F" />
    </rdf:Seq>
    </items>
  </channel>

  <item rdf:about="https://chouprogramming.blog-sim.com/daily/2015-01-17-%E3%80%8C%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB%E3%82%B0%E3%83%A9%E3%82%B9%E3%80%8D%E5%80%8B%E4%BA%BA%E5%90%91%E3%81%91%E8%B2%A9%E5%A3%B2%E4%B8%AD%E6%AD%A2">
    <link>https://chouprogramming.blog-sim.com/daily/2015-01-17-%E3%80%8C%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB%E3%82%B0%E3%83%A9%E3%82%B9%E3%80%8D%E5%80%8B%E4%BA%BA%E5%90%91%E3%81%91%E8%B2%A9%E5%A3%B2%E4%B8%AD%E6%AD%A2</link>
    <title>2015/01/17/「グーグルグラス」個人向け販売中止</title>
    <description>「グーグルグラス」個人向け販売中止

http://www.nikkei.com/article/DGXLASGM16H1J_W5A110C1EAF000/
 (リンク先：日経新聞)

　米国や英国で販売されていたグーグルグラスが個人向け販売を中止して法人向け販売に展開した。その外見は普通の眼鏡に小...</description>
    <content:encoded><![CDATA[「グーグルグラス」個人向け販売中止<br />
<br />
<a href="http://www.nikkei.com/article/DGXLASGM16H1J_W5A110C1EAF000/" title="">http://www.nikkei.com/article/DGXLASGM16H1J_W5A110C1EAF000/<br />
</a> (リンク先：日経新聞)<br />
<br />
　米国や英国で販売されていたグーグルグラスが個人向け販売を中止して法人向け販売に展開した。その外見は普通の眼鏡に小型のスコープのような機器が取り付けられていてそれが周囲から盗撮の心配が上がったのだ。<br />
<br />
　すでに法人向けには作業を効率的に行うものとして在庫確認などが素早くできる開発をしている。またヘッドマウントディスプレイのような装着感も少なく拡張現実(AR)がより現実さを帯びてくるだろう。<br />
<br />
　外に目を向けてみれば新聞配達や郵便配達、宅配便などはまだ人間が行っている。全てを自動化するのはまだまだ先のようだがグーグルグラスを活用することで次の目的地の経路を最短で表示し作業を効率化するのは比較的容易ではないだろうか。可能性は無限にある。]]></content:encoded>
    <dc:subject>日記</dc:subject>
    <dc:date>2015-01-18T06:43:50+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/manga/2015-01-12-%E5%AF%84%E7%94%9F%E7%8D%A3">
    <link>https://chouprogramming.blog-sim.com/manga/2015-01-12-%E5%AF%84%E7%94%9F%E7%8D%A3</link>
    <title>2015/01/12/寄生獣</title>
    <description>寄生獣
(リンク先：amazon)

　岩明均氏による漫画作品。漫画を読んでいると中だるみのようなものを感じてしまう作品がいくつもあるがこの作品ではそういうものは一切ない。無駄が全くないのだ。漫画家のなかでこれほど話を作るのがうまい人はそうはいないだろう。

　去年映画の実写版が公開されたが限られた...</description>
    <content:encoded><![CDATA[<strong><a href="http://www.amazon.co.jp/%E5%AF%84%E7%94%9F%E7%8D%A3-%E5%AE%8C%E5%85%A8%E7%89%88-1-KC%E3%83%87%E3%83%A9%E3%83%83%E3%82%AF%E3%82%B9-%E3%82%A2%E3%83%95%E3%82%BF%E3%83%8C%E3%83%BC%E3%83%B3/dp/4063346641" title="">寄生獣</a><br />
</strong><span style="color: #414244; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; line-height: 22.1000003814697px; background-color: #fafafa;">(リンク先：amazon)</span><br />
<br />
　岩明均氏による漫画作品。漫画を読んでいると中だるみのようなものを感じてしまう作品がいくつもあるがこの作品ではそういうものは一切ない。無駄が全くないのだ。漫画家のなかでこれほど話を作るのがうまい人はそうはいないだろう。<br />
<br />
　去年映画の実写版が公開されたが限られた時間内でこの作品の素晴らしさを表現できたのだろうか。最近オリジナルより原作があらかじめあるものが多く見受けられる。それは映画に限らずの話だが脚本家は己の才能だけで勝負をしてほしい。<br />
<br />
<span style="color: #414244; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; line-height: 22.1000003814697px; background-color: #fafafa;">オススメ度</span><br style="line-height: 22.1000003814697px; color: #414244; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; background-color: #fafafa;" /><span style="color: #414244; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; line-height: 22.1000003814697px; background-color: #fafafa;">★★★★★(5/5)</span><br style="line-height: 22.1000003814697px; color: #414244; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; background-color: #fafafa;" /><span style="color: #414244; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; line-height: 22.1000003814697px; background-color: #fafafa;">(完結：全8巻)</span>]]></content:encoded>
    <dc:subject>漫画</dc:subject>
    <dc:date>2015-01-12T17:39:29+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/manga/2015-01-12-%E3%83%94%E3%83%B3%E3%83%9D%E3%83%B3">
    <link>https://chouprogramming.blog-sim.com/manga/2015-01-12-%E3%83%94%E3%83%B3%E3%83%9D%E3%83%B3</link>
    <title>2015/01/12/ピンポン</title>
    <description>ピンポン
(リンク先：amazon)

　松本大洋氏による漫画作品。この作品を好きな理由のひとつとして長すぎないことが大きいかもしれない。全5巻、数時間で読むことができ読了後は後味が良くてストーリーも面白い。

　主人公を含め登場人物はそれぞれ嫉妬や重圧や挫折などに苦しんでいて人間味が溢れている。そ...</description>
    <content:encoded><![CDATA[<strong><a href="http://www.amazon.co.jp/%E3%83%94%E3%83%B3%E3%83%9D%E3%83%B3-Big-spirits-comics-special/dp/4091847366" title="">ピンポン</a></strong><br />
(リンク先：amazon)<strong><br />
<br />
</strong>　松本大洋氏による漫画作品。この作品を好きな理由のひとつとして長すぎないことが大きいかもしれない。全5巻、数時間で読むことができ読了後は後味が良くてストーリーも面白い。<br />
<br />
　主人公を含め登場人物はそれぞれ嫉妬や重圧や挫折などに苦しんでいて人間味が溢れている。そこが読者の共感を誘い引き込むのだ。<br />
<br />
オススメ度<br />
★★★★★(5/5)<br />
(完結：全5巻)]]></content:encoded>
    <dc:subject>漫画</dc:subject>
    <dc:date>2015-01-12T16:51:48+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/daily/2015-01-11">
    <link>https://chouprogramming.blog-sim.com/daily/2015-01-11</link>
    <title>2015/01/11/ミドリムシで、空を飛ぶ。</title>
    <description>ミドリムシで、空を飛ぶ。

http://www.nikkei.com/article/DGXMZO81333380V21C14A2000000/
(リンク先：日経新聞)

　中学生のころミドリムシの勉強をして以来その名を聞かなかったが、現在かなりの注目を集めている。栄養が豊富で食事やサプリメントと...</description>
    <content:encoded><![CDATA[<strong>ミドリムシで、空を飛ぶ。<br />
<br />
</strong><a href="http://www.nikkei.com/article/DGXMZO81333380V21C14A2000000/" title="">http://www.nikkei.com/article/DGXMZO81333380V21C14A2000000/</a><br />
(リンク先：日経新聞)<strong><br />
<br />
</strong>　中学生のころミドリムシの勉強をして以来その名を聞かなかったが、現在かなりの注目を集めている。栄養が豊富で食事やサプリメントとして注目されているだけでなく、飛行機の燃料として使う動きが見られているのだ。<br />
<br />
　この記事を見て私が最初に思ったことは「よくミドリムシを燃料にしようとしたな」だ。課題も多いらしく燃料にするためには莫大な量のミドリムシが必要で、それらは光合成なしでは増殖しない。横が透明なプールで満遍なく人口太陽を照らし続け、一定の量を安定して生み出すことができれば新たな燃料革命が起こるだろう。<br />
<br />
　夜になる時間が短い北欧やカナダなどでこれらの事業を行えば開発コストも抑えられ日本の経済も明るくなるのではないだろうか。]]></content:encoded>
    <dc:subject>日記</dc:subject>
    <dc:date>2015-01-12T11:04:07+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/lisp/%E5%86%8D%E5%B8%B0%E9%96%A2%E6%95%B0">
    <link>https://chouprogramming.blog-sim.com/lisp/%E5%86%8D%E5%B8%B0%E9%96%A2%E6%95%B0</link>
    <title>Lispの再帰関数</title>
    <description>指数関数

xを任意の非負実数、mを任意の非負整数とするとき、xのm乗の再帰関数mypwrを定義します。

if関数
****
(defun mypwr (x m)
&amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp; &amp;amp;nbsp;(if (= m 0)
&amp;amp;nbsp; &amp;amp;nbsp; ...</description>
    <content:encoded><![CDATA[<strong>指数関数<br />
<br />
</strong>xを任意の非負実数、mを任意の非負整数とするとき、xのm乗の再帰関数mypwrを定義します。<br />
<br />
if関数<br />
****<br />
(defun mypwr (x m)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (= m 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(* x (mypwr x (- m 1)))))<br />

<div>; [1]&gt; (mypwr 2 3)</div>
<div>; 8.0</div>
<div>; [2]&gt; (mypwr 0.5 3)</div>
<div>; 0.125</div>
****<br />
<br />
cond関数<br />
****<br />
(defun mypwr (x m)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cond ((= m 0)&nbsp;1.0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(T (* x (mypwr x (- m 1))))))<br />

<div>; [1]&gt; (mypwr 2 3)</div>
<div>; 8.0</div>
<div>; [2]&gt; (mypwr 0.5 3)</div>
<div>; 0.125</div>
****<br />
<br />
xが2、mが3の場合について考えてみましょう。if文で"(= m 0)"と記述されているので、条件に当てはまらないときの手続きである"(* x (mypwr x (- m 1)))))"を行います。"(* 2 (mypwr 2 2))))"と解釈ができるので"(mypwr 2 2)"について考えます。同様にmは0ではないので"(* 2 (mypwr 2 1))))"となり、"(mypwr 2 1)"でもmは0ではないので"(* 2 (mypwr 2 0))))"となります。"(mypwr 2 0)"ではmの値が0なので1.0を返し、"(mypwr 2 1)"は1.0なので置き換えると"(* 2 1.0)"となります。また同様に繰り返していくと"(mypwr 2 2.0)"、"(mypwr 2 4.0)"となり最終的な答えは8.0になります。<br />
<br />
<strong>平方根</strong><br />
<br />
任意の正実数cの平方根c^(1/2)を求める関数mysqrtを定義してみましょう。実数xを引数とする実関数をF(x)=x^(2)-cとするとき、F(x)が0ならば等式の関係が成り立ちます。xとcをそれぞれ2乗している理由は最終的な答えをxでだすためです。x^(2)=cならばxを返せばその値はc^(1/2)になります。さて、この方程式を求めるにはニュートン法と呼ばれる再帰的な計算方法でその近似値解を求めます。初期値を正の実数x(0)にしたときの近似値解x(n)は<br />
<br />
x(n)=x(n-1)-F(x(n-1))/f(x(n-1))<br />
<br />
になります。x(0)はxの最初の解、x(n)は上の式を再帰的にn回繰り返したときに求められる解のことです。その2つの解の間にはx(1),x(2),...,x(n-2),x(n-1)とあります。さらに、この式でのf(x(n-1))はF(x(n-1))の導関数を表します。つまり、f(x(n-1))はF(x(n-1))を微分したものになります。これらのことをF(x)=x^(2)-cに置き換えてみると<br />
<br />
x(n)=x(n-1)-(x(n-1)^(2)-c)/(2x(n-1))<br />
<br />
になり、分数部分を分解して再度整理すると<br />
<br />
x(n)=x(n-1)/2+c/(2x(n-1))<br />
<br />
Lispで記述すると<br />
<br />
****<br />
(defun better (x c)<br />

<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(+ (/ x 2.0)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(/ c (* 2.0 x))))</div>
****<br />
<br />
になりました。さて、ニュートン法とはnの値が大きくなればなるほど解に収束していきますが計算を永遠に続けていくわけにはいきません。どこかで誤差(妥協)を決めなければならないのです。それは人それぞれですが、今回は誤差0.001で考えてみましょう。<br />
<br />
実際の解F(x)と再帰的に求めた解F(x(n))の誤差を求めるにはその２つの解の絶対値を求めて、それが誤差未満かどうかを判断します。絶対値を求める関数は前回の真偽の判定で定義した関数absoluteを使用します。<br />
<br />
****<br />

<div>(defun absolute (x)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cond ((&lt; x 0) (- 0 x))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(T x)))</div>
****<br />
<br />
関数absoluteで求めた値が誤差より小さければ計算を止めるように命令をすればよいので、ここでは"T"を返すようにします。誤差を変数errと置くと<br />
<br />
|F(x)-F(x(n))|&lt;err<br />
<br />
F(x)を変数a、F(x(n))を変数bと置いてLispで記述したときの関数nearは<br />
<br />
****<br />

<div>(defun near (a b err)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(&lt; (absolute (- a b)) err))</div>
****<br />
<br />
になります。最後に関数nearで"T"が帰ってきた場合はxを返し、"NIL"が帰ってきた場合はxを再度計算します。つまり、xの値を関数betterでさらに計算した値に置き換える処理をします。上記の処理をする関数の名前をmysqrt-coreとすると<br />
<br />
****<br />

<div>(defun mysqrt-core (c x err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (near c (* x x) err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(mysqrt-core c (better x c) err)))</div>
****<br />
<br />
になり、関数mysqrtは<br />
<br />
****<br />

<div>(defun mysqrt (c)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(mysqrt-core c 1.0 0.001))</div>
****<br />
<br />
と記述ができます。<br />
<br />
****<br />
(defun better (x c)<br />

<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(+ (/ x 2.0)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(/ c (* 2.0 x))))<br />

<div>(defun absolute (x)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cond ((&lt; x 0) (- 0 x))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(T x)))<br />
(defun near (a b err)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(&lt; (absolute (- a b)) err))<br />

<div>(defun mysqrt-core (c x err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (near c (* x x) err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(mysqrt-core c (better x c) err)))<br />

<div>(defun mysqrt (c)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(mysqrt-core c 1.0 0.001))<br />

<div>; [1]&gt; (mysqrt 2)</div>
<div>; 1.4142157</div>
<div>; [2]&gt; (mysqrt 5)</div>
<div>; 2.2360687<br />

<div>; [3]&gt; (mysqrt 4)</div>
<div>; 2.0</div>
</div>
</div>
</div>
</div>
</div>
****<br />
<br />
<strong>演習</strong><br />
任意の正実数cと2以上の任意の整数mが仮引数として与えられたときのcのm乗根(&gt;0)を計算する関数rootを定義し適当な値で評価せよ。なお、初期値xは1.0、誤差errは0.001とし、必要な関数は自分で定義をすること。<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<strong>演習回答<br />
</strong>****<br />

<div>(defun better (x c m)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(+ (* (- 1 (/ 1 m)) x)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(/ c (* m (mypwr x (- m 1))))))<br />

<div>(defun absolute (x)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cond ((&lt; x 0) (- 0 x))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(T x)))<br />
(defun near (a b err)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(&lt; (absolute (- a b)) err))<br />
(defun mypwr (x m)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (= m 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(* x (mypwr x (- m 1)))))<br />

<div>(defun root-core (c m x err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (near c (mypwr x m) err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(root-core c m (better x c m) err)))<br />
(defun root (c m)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(root-core c m 1.0 0.001))<br />

<div>; [1]&gt; (root 3 8)</div>
<div>; 1.1472127</div>
<div>; [2]&gt; (root 4 2)</div>
<div>; 2.0<br />

<div>; [3]&gt; (root 15 4)</div>
<div>; 1.9679902</div>
</div>
</div>
</div>
</div>
****<br />
<br />
<strong>演習解説</strong><br />
この問題でポイントになるのはF(x)からx(n)が求められるか、x(n)をLispで記述できるかの2点です。それさえできれば2乗根と同じ要領でできます。<br />
<br />
まず、cのm乗根をF(x)=x^(m)-cとするときf(x)はm*x^(m-1)となります。そしてx(n)はニュートン法の式に代入していきx(n)=x(n-1)-(x(n-1)^(m)-c)/(m*x(n-1)^(m-1))を得ます。式を整理してみるとx(n)=(1-(1/m))*x(n-1)+c/(m*x(n-1)^(m-1))となりx(n)を求めることができました。<br />
<br />
次にx(n)をLispで記述するには、xのm乗を計算しなくてはなりません。指数の計算に少し戸惑った人がいると思いますがこのページの最初の定義式に指数を計算する関数mypwrがあるのでそれを利用します。]]></content:encoded>
    <dc:subject>Lisp</dc:subject>
    <dc:date>2014-11-23T22:44:30+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/lisp/%E7%9C%9F%E5%81%BD%E3%81%AE%E5%88%A4%E5%AE%9A%E3%82%92%E3%81%97%E3%82%88%E3%81%86">
    <link>https://chouprogramming.blog-sim.com/lisp/%E7%9C%9F%E5%81%BD%E3%81%AE%E5%88%A4%E5%AE%9A%E3%82%92%E3%81%97%E3%82%88%E3%81%86</link>
    <title>Lispの真偽判定</title>
    <description>比較演算子を使ってみよう

比較演算子とは2つの対象の関係性を調べるものです。具体的には&amp;quot;&amp;amp;lt;&amp;quot;,&amp;quot;=&amp;quot;,&amp;quot;&amp;amp;gt;&amp;quot;などです。使い方は関数と一緒で

&amp;quot;(&amp;amp;lt; 引数1 引数2)&amp;quot;
&amp;quot;(= 引数1 引数2)&amp;quot;
&amp;quot;(&amp;amp;gt; 引数1 引数2)&amp;quot;

などと記述します。また、これらは真の場合&amp;quot;T&amp;quot;...</description>
    <content:encoded><![CDATA[<strong>比較演算子を使ってみよう<br />
<br />
</strong>比較演算子とは2つの対象の関係性を調べるものです。具体的には"&lt;","=","&gt;"などです。使い方は関数と一緒で<br />
<br />
"<strong>(&lt; 引数1 引数2)</strong>"<br />
"<strong>(= 引数1 引数2)</strong>"<br />
"<strong>(&gt; 引数1 引数2)</strong>"<br />
<br />
などと記述します。また、これらは真の場合"<strong>T</strong>"、偽の場合"<strong>NIL</strong>"を返します。<br />
<br />
****<br />
; [1]&gt; (&lt; 1 2)<br />
; T<br />
; [2]&gt; (&lt; 2 1)<br />
; NIL<br />
; [3]&gt; (&lt; 1 1)<br />
; NIL<br />
; [4]&gt; (&gt; 2 1)<br />
; T<br />
; [5]&gt; (&gt; 1 2)<br />
; NIL<br />
; [6]&gt; (= 2 1)<br />
; NIL<br />
; [7]&gt; (= 2 2)<br />
; T<br />
****<br />
<br />
"(&lt; 1 2)"を見てみると、1は2より小さいのでこの場合はT(真)を返しています。次に"(&lt; 2 1)"を見てみると、1は2より大きくないのでNIL(偽)を返しています。"&gt;"は"&lt;"の逆関係、"="は同値関係を調べるときに使われます。また、文字列の同値関係も調べたい場合は次のequal関数を使います。<br />
<br />
"<strong>(equal 引数1 引数2)</strong>"<br />
<br />
****<br />
; [1]&gt; (equal 'abc 'def)<br />
; NIL<br />
; [2]&gt; (equal 'abc 'abc)<br />
; T<br />
; [3]&gt; (equal 2 2)<br />
; T<br />
; [4]&gt; (equal 2 3)<br />
; NIL<br />
; [5]&gt; (equal 'abc 3)<br />
; NIL<br />
****<br />
<br />
<strong>論理演算子を使ってみよう</strong><br />
<br />
論理演算子とは真(True)か偽(False)の値しかもたないデータの演算のことをいいます。具体的には"not","and","or"などです。使い方は<br />
<br />
"<strong>(not 引数)</strong>"<br />
"<strong>(and 引数1 引数2 ...)</strong>"<br />
"<strong>(or 引数1 引数2 ...)</strong>"<br />
<br />
などと記述します。論理演算子も返り値は"<strong>T</strong>"または"<strong>NIL</strong>"になります。<br />
<br />
****<br />

<div>; [1]&gt; (and (&lt; 1 2) (&lt; 3 4) (&lt; 5 6))</div>
<div>; T</div>
<div>; [2]&gt; (and (&lt; 1 2) (&lt; 3 4) (&gt; 5 6))</div>
<div>; NIL</div>
<div>; [3]&gt; (or (&lt; 1 2) (&lt; 3 4) (&gt; 5 6))</div>
<div>; T</div>
<div>; [4]&gt; (or (&gt; 1 2) (&gt; 3 4) (&gt; 5 6))</div>
<div>; NIL</div>
<div>; [5]&gt; (not (or (&gt; 1 2) (&gt; 3 4) (&gt; 5 6)))</div>
<div>; T</div>
****<br />
<br />
and関数は引数が全て真であれば真を返り値として返すものです。"(and (&lt; 1 2) (&lt; 3 4) (&lt; 5 6))"では、引数の値が全て真になるので真を返します。ところが、下の"(and (&lt; 1 2) (&lt; 3 4) (&gt; 5 6))"では第3引数である"(&gt; 5 6)"の値が偽となるので偽を返します。<br />
<br />
or関数は引数がひとつでも真であれば真を返り値として返すものです。"(or (&lt; 1 2) (&lt; 3 4) (&gt; 5 6))"では第1引数と第2引数が真であるので真を返します。ところが、下の"(or (&gt; 1 2) (&gt; 3 4) (&gt; 5 6))"では全ての引数が偽となるので偽を返します。<br />
<br />
not関数は引数が真であれば偽を返し、偽であれば真を返すものです。"(or (&gt; 1 2) (&gt; 3 4) (&gt; 5 6))"は偽でしたのでnot関数で囲うと真を返します。<br />
<br />
<strong>条件分岐を使ってみよう<br />
<br />
</strong>Lispには分岐を制御するcond関数とif関数が用意されています。<br />
<br />
"<strong>(cond (条件1 手続き1) (条件2 手続き2) ...)</strong>"<br />
"<strong>(if 条件 手続き 条件に当てはまらないときの手続き)</strong>"<br />
<br />
cond関数は条件をいくつでも記述することができ、条件1から順番に調べていきます。条件が真になり次第その手続きを行います。<br />
<br />
****<br />

<div>(defun absolute (x)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cond ((&lt; x 0) (- 0 x))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((= x 0) 0)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((&gt; x 0) x)))</div>
<div>; [1]&gt; (absolute 3)</div>
<div>; 3</div>
<div>; [2]&gt; (absolute 0)</div>
<div>; 0</div>
<div>; [3]&gt; (absolute -3)</div>
<div>; 3</div>
****<br />
<br />
3を入力した場合で考えてみましょう。absolute関数では初めの条件として"(&lt; x 0)"が記述されています。それは入力した数値が0よりも小さければ真を返すという意味なので偽を返します。続いて"(= x 0)"では0であれば真を返すという意味なのでここでも偽を返します。最後の"(&gt; x 0)"では入力した数値が0よりも大きければ真を返すという意味なので真を返してそこの手続きを行います。手続きでは入力した数値をそのまま返すというものなので3が表示されました。<br />
<br />
cond関数のよいところは条件をいくつでも記述ができることです。しかし、全ての条件に当てはまらないときは動作が保障されなくなってしまいます。それを防ぐ方法として最後の条件は必ず真になるようにします。つまり、条件を"T"とあらかじめ記述しておくのです。先ほどのabsolute関数では条件に当てはまらないということはないのですが、このように記述する癖をつけることで他の関数を定義するときに、条件がひとつも当てはまらなくなってしまうものがあるという可能性を事前に回避することができます。<br />
<br />
****<br />

<div>(defun absolute (x)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(cond ((&lt; x 0) (- 0 x))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((= x 0) 0)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(T x)))</div>
****<br />
<br />
if関数はcond関数とは違い条件をひとつしか記述することができませんが、手続きのなかにif関数を記述するとcond関数のように扱うこともできます。<br />
<br />
****<br />
(defun renum (x)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (&lt; x 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (= x -3) 1 2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0))<br />

<div>; [1]&gt; (absolute2 -3)</div>
<div>; 1</div>
<div>; [2]&gt; (absolute2 -2)</div>
<div>; 2</div>
<div>; [3]&gt; (absolute2 0)</div>
<div>; 0</div>
****<br />
<br />
<strong>演習<br />
</strong>if関数を用いて引数の絶対値を返す関数absolute2を定義せよ。<br />
上の関数absoluteと同様に正数、0、負数の順で評価せよ。<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<strong>演習解答</strong><br />
****<br />
(defun absolute2 (x)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(if (&lt; x 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(- 0 x)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x))<br />

<div>; [1]&gt; (absolute2 3)</div>
<div>; 3</div>
<div>; [2]&gt; (absolute2 0)</div>
<div>; 0</div>
<div>; [3]&gt; (absolute2 -3)</div>
<div>; 3</div>
****<br />
<strong></strong>]]></content:encoded>
    <dc:subject>Lisp</dc:subject>
    <dc:date>2014-11-21T15:52:13+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%AE-hello-%20world-">
    <link>https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%AE-hello-%20world-</link>
    <title>Lispの文字出力</title>
    <description>Lispの&amp;quot;Hello, World&amp;quot;

プログラミングで文字列を出力するとき、大抵の本にはこの文言が書かれていると思います。Lispで文字列を出力するときはformat関数を使います。この関数にはいろいろな使い方があってすべてを把握するのは大変ですが&amp;quot;Hello, World&amp;quot;を出力するだけなら簡...</description>
    <content:encoded><![CDATA[<span style="font-size: large;"><strong><span style="font-size: 14px;">Lispの"Hello, World"</span><br />
</strong><span style="font-size: 14px;"><br />
プログラミングで</span></span>文字列を出力するとき、大抵の本にはこの文言が書かれていると思います。Lispで文字列を出力するときはformat関数を使います。この関数にはいろいろな使い方があってすべてを把握するのは大変ですが"Hello, World"を出力するだけなら簡単に扱うことが出来ます。<br />
<br />
"<strong>(format t "文字列")</strong>"<br />
<br />
このようにすれば文字列を出力することができます。format関数の後ろにあるtは標準出力に出力することを表します。<br />
<br />
****<br />
; [1]&gt; (format t "Hello, World")<br />
; Hello, World
<div>; NIL</div>
****]]></content:encoded>
    <dc:subject>Lisp</dc:subject>
    <dc:date>2014-11-17T17:39:33+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/lisp/%E9%96%A2%E6%95%B0%E3%81%AE%E5%AE%9A%E7%BE%A9">
    <link>https://chouprogramming.blog-sim.com/lisp/%E9%96%A2%E6%95%B0%E3%81%AE%E5%AE%9A%E7%BE%A9</link>
    <title>Lispの関数定義</title>
    <description>関数を定義しよう

目的に合った処理をさせるために関数を自分で作ることができます。関数を定義するためには定義をするための関数を使います。

&amp;quot;(defun 関数名 (仮引数1 仮引数2 ...) 仮引数を含む手続き)&amp;quot;

仮引数とは実際の具体的な数字や文字などではなく、手続きに組み込まれる予定の仮の...</description>
    <content:encoded><![CDATA[<strong>関数を定義しよう<br />
</strong><strong><br />
</strong>目的に合った処理をさせるために関数を自分で作ることができます。関数を定義するためには定義をするための関数を使います。<br />
<br />
"<strong>(defun 関数名 (仮引数1 仮引数2 ...) 仮引数を含む手続き)</strong>"<br />
<br />
仮引数とは実際の具体的な数字や文字などではなく、手続きに組み込まれる予定の仮の値のことを仮引数といいます。そこに1や2など、実際の値(実引数)が読み込まれるたびに順次置換されていきます。<br />
<br />
****<br />
(defun add (x y) (+ x y))<br />
****<br />
<br />
これで関数の定義はできました。関数の使い方は前の記事のとおり"<strong>(関数名 引数1 引数2&nbsp;</strong><strong style="border: 0px; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; list-style: none; line-height: 22.1000003814697px; color: #414244; background-color: #fafafa;">...</strong><strong>)</strong>"です。<br />
<br />
****<br />

<div>; [1]&gt; (add 2 3)</div>
<div>; 5</div>
****<br />
<br />
<strong>引数がない関数の定義をしよう<br />
<br />
</strong>関数の定義は必ず引数がなくとも定義することができます。使い方の使い方の例を見てみましょう。<br />
<br />
"<strong>(defun 関数名 () 仮引数がない手続き)</strong>"<br />
<br />
****<br />

<div>(defun three () (+ 1 2))<br />
; [1]&gt; (three)<br />
; 3</div>
<div>
<div>(defun tmp () (three))</div>
<div>; [2]&gt; (tmp)</div>
<div>; 3</div>
</div>
****<br />
<br />
文字を扱う場合は前にアポストロフィを記述します。<br />
<br />
****<br />

<div>(defun moji () 'test)</div>
<div>; [2]&gt; (moji)</div>
<div>; TEST</div>
****<br />
<br />
引数なしの関数を定義するものに類似としてsetq関数があります。<br />
<br />
"<strong>(setq 変数 値)</strong>"<br />
<br />
変数とは値を格納しておくデータ名のことです。defun関数と違う点は変数なので新たな関数に組み込むことができます。<br />
<br />
****<br />

<div>(setq ten 10)</div>
<div>; [1]&gt; ten</div>
<div>; 10</div>
<div>(defun add () (+ ten 3))</div>
<div>; [2]&gt; (add)</div>
<div>; 13</div>
****<br />
<br />
<strong>関数名を定義しない関数を定義しよう<br />
<br />
</strong>関数名を定義しないその場限りの関数も定義することができます。<br />
<br />
"<strong>((lambda (仮引数1 仮引数2 ...) 仮引数を含む手続き) 実引数1 実引数2 ...)</strong>"<br />
<br />
****<br />

<div>((lambda (x) (* x x x x)) 3)</div>
<div>; 81<br />

<div>((lambda (x y) (- x y)) 5 2)</div>
<div>; 3</div>
</div>
****<br />
lamda関数に類似の関数としてlet関数と呼ばれるものがあります。2つの関数の違いとしてlet関数はdefun関数に組み込むことができます。<br />
<br />
"<strong>(let ((仮引数1 実引数1)&nbsp;</strong><strong>(仮引数2 実引数2) ...) 仮引数を含む手続き</strong><strong>)</strong>"<br />
<br />
****<br />

<div>(defun sum ()</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (let ((tmp1 5)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(tmp2 3))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(+ tmp1 (+ tmp1 tmp2))))</div>
<div>; [1]&gt; (sum)</div>
<div>; 13</div>
****<br />
<br />
<strong>演習</strong><br />
<br />
文字列chou-programmingを引数なしの関数kansuu1と定義し、kansuu1を評価せよ。<br />
kansuu1を使って文字列chou-programmingを返すkansuu2を定義し、評価せよ。<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<strong>演習解答</strong><br />
****<br />
(defun kansuu1 () 'chou-programming)<br />
; [1]&gt; (kansuu1)<br />
; CHOU-PROGRAMMING<br />
(defun kansuu2 () (kansuu1))<br />
; [2]&gt; (kansuu2)<br />
; CHOU-PROGRAMMING<br />
****]]></content:encoded>
    <dc:subject>Lisp</dc:subject>
    <dc:date>2014-11-17T17:03:32+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%AE%E5%9F%BA%E6%9C%AC">
    <link>https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%AE%E5%9F%BA%E6%9C%AC</link>
    <title>Lispの演算</title>
    <description>最初に

・開発環境はwindows7(64bit)。
・特に記述が無い場合はCLISP(ver2.49)を使う。
・Lispの始まりと終わりは****で区切る。
・関数の定義以外の部分は&amp;quot;;&amp;quot;を先頭に記述する。
・コードはGitHubからダウンロードできる。

インタプリタを起動する

コマンドプ...</description>
    <content:encoded><![CDATA[<strong></strong><span style="font-size: 14px;"><strong>最初に</strong></span><br />
<br />
・開発環境はwindows7(64bit)。<br />
・特に記述が無い場合はCLISP(ver2.49)を使う。<br />
・Lispの始まりと終わりは****で区切る。<br />
・関数の定義以外の部分は";"を先頭に記述する。<br />
・コードはGitHubからダウンロードできる。<br />
<br />
<strong><span style="font-size: 14px;">インタプリタを起動する</span><br />
</strong><br />
コマンドプロンプトを立ち上げたら"<strong>clisp</strong>"と入力する。<br />

<div><br />
<span style="font-size: 14px;"><strong>インタプリタを終了する<br />
</strong></span><br />
終了するときは"<strong>(exit)</strong>"もしくは"<strong>(bye)</strong>"と入力する。<br />
<br />
<span style="font-size: large;"><strong><span style="font-size: 14px;">簡単な計算をしてみよう</span><br />
</strong></span><br />
Lispでなにか処理をさせたい場合は関数と呼ばれるものを使います。例えばある数字とある数字を足したいときは関数である"+"を使います。また関数が使うデータのことを引数と呼びます。先の例での引数はある数字のことです。<br />
<br />
記述の仕方は"<strong>(関数名 引数1 引数2 ...)</strong>"と必ず括弧の中に記述します。<br />
先の例で記述すると"<strong>(+ ある数字 ある数字)</strong>"となります。<br />
<br />
四則演算の関数<br />
加算："+"<br />
減算："-"<br />
乗算："*"<br />
除算："/"<br />
<br />
****<br />

<div>; [1]&gt; (+ 1 2)</div>
<div>; 3</div>
<div>; [2]&gt; (- 1 2)</div>
<div>; -1</div>
<div>; [3]&gt; (* 2 3)</div>
<div>; 6<br />

<div>; [4]&gt; (/ 7 2)</div>
<div>; 7/2<br />
****<br />
<br />
<span size="4" style="font-size: large;"><b><span style="font-size: 14px;">複雑な計算をしてみよう</span><br />
<br />
</b></span>上では2つの引数を使いましたが、それ以上の引数を使うことができますし、計算結果を1つの引数として使うこともできます。<br />
<br />
****<br />
; [1]&gt; (+ 1 2 3 4 5)<br />
; 15<br />
; [2]&gt; (- 30 2 3 4 5)<br />
; 16<br />
; [3]&gt; (/ 36 6 3)<br />
; 2<br />
; [4]&gt; (+ (- 8 (/ 6 3)) (* 7 2))<br />
; 20<br />
****<br />
<br />
引数がたくさんある場合、左から順番に処理をします。"(/ 36 6 3)"を見てください。左側から処理をするのであれば36を6で割り、その答えを3で割ります。その結果答えは2となります。6を3で割りその答えを使って36を割ると、結果は18となり答えが変わってしまいます。<br />
<br />
同様に"(+ (- 8 (/ 6 3)) (* 7 2))"も考えてみましょう。一番外側の括弧は関数"+"を使っています。その引数は"(- 8 (/ 6 3))"と"(* 7 2)"です。この2つの引数も同様に関数を使って計算をしていますので"(- 8 (/ 6 3))"に注目して考えてみましょう。一番外側の括弧は関数"-"を使っています。その引数は"8"と"(/ 6 3)"です。"8"は計算をする必要はありませんが"(/ 6 3)"はさらに計算が出来ます。"(/ 6 3)"の結果は2です。つまり"(- 8 2)"となり結果は6となります。"(* 7 2)"に注目すると結果は14となので"(+ (- 8 (/ 6 3)) (* 7 2))"と"(+ 6 14)"は同じ式として表すことができ、計算結果は20となります。<br />
<br />
<span style="font-size: 14px;"><strong>整数型と実数型</strong></span><br />
<br />
計算する時に整数の部分のみを取り出した整数型と実数の近似を表現できる実数型は使い分けることができます。計算で1つでも実数型が含まれていれば、その計算は実数型として計算されます。逆に、1つでも実数型が含まれていなければその計算は整数型として計算されます。分数の計算では実数型を使っていれば小数点まで表示されますが、整数型のみだと分数表示されます。<br />
<br />
****<br />
; [1]&gt; (+ 2 3)<br />
; 5<br />
; [2]&gt; (+ 2.0 3.0)<br />
; 5.0<br />
; [3]&gt; (+ 2 3.0)<br />
; 5.0<br />
; [4]&gt; (+ 2.0 3)<br />
; 5.0<br />
; [5]&gt; (+ (* 3.0 4) 5)<br />
; 17.0<br />
; [6]&gt; (/ 2 4)<br />
; 1/2<br />
; [7]&gt; (/ 2 4.0)<br />
; 0.5<br />
; [8]&gt; (/ 13 7.0)<br />
; 1.8571428<br />
****<br />
<br />
<strong>演習<br />
</strong>次の式を評価せよ。<br />
1. (/ 1 (/ 15 3))<br />
2. (/ 1 (/ 15.0 3))<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<strong>演習解答</strong><br />
****<br />
; [1]&gt; (/ 1 (/ 15 3))<br />
; 1/5<br />
; [2]&gt; (/ 1 (/ 15.0 3))<br />
; 0.2<br />
****</div>
</div>
</div>]]></content:encoded>
    <dc:subject>Lisp</dc:subject>
    <dc:date>2014-11-11T14:49:59+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
  <item rdf:about="https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%A8%E3%81%AF%E3%81%AA%E3%82%93%E3%81%9E%EF%BC%9F">
    <link>https://chouprogramming.blog-sim.com/lisp/lisp%E3%81%A8%E3%81%AF%E3%81%AA%E3%82%93%E3%81%9E%EF%BC%9F</link>
    <title>Lispとは</title>
    <description>Lispとは(リンク先：Wikipedia)

　Lispはプログラミングの組む感覚が非常に強い言語です。プログラミングの面白さに触れてみたいのであればこの言語をおすすめします。現実ではアプリケーションや金融関係の決済システムで使われていますが、CやJavaと比べると使う人は少ないでしょう。&amp;amp;nbs...</description>
    <content:encoded><![CDATA[<span style="color: #414244; font-family: メイリオ, Meiryo, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'ＭＳ Ｐゴシック', sans-serif; font-size: 13px; line-height: 18.2000007629395px; text-align: right; background-color: #fafafa;"><a href="http://ja.wikipedia.org/wiki/LISP" title="">Lispとは</a>(リンク先：Wikipedia)<br />
<br />
　Lispはプログラミングの組む感覚が非常に強い言語です。プログラミングの面白さに触れてみたいのであればこの言語をおすすめします。現実ではアプリケーションや金融関係の決済システムで使われていますが、CやJavaと比べると使う人は少ないでしょう。&nbsp;</span>]]></content:encoded>
    <dc:subject>Lisp</dc:subject>
    <dc:date>2014-11-05T15:23:18+09:00</dc:date>
    <dc:creator>ヨシ</dc:creator>
    <dc:publisher>NINJA BLOG</dc:publisher>
    <dc:rights>ヨシ</dc:rights>
  </item>
</rdf:RDF>
