Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > c5653a35bb94fee65ffe21230992c863 > files > 409

linbox-doc-1.2.1-1.fc15.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>linbox: examples/graph-charpoly.C</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">linbox</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">examples/graph-charpoly.C</div>  </div>
</div>
<div class="contents">
<p>Compute the integer characteristic polynomial of symetric matrices with (0,1) coefficients. Example for Pr G. Royle.</p>
<div class="fragment"><pre class="fragment"><span class="comment">/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */</span>
<span class="comment">// vim:sts=8:sw=8:ts=8:noet:sr:cino=&gt;s,f0,{0,g0,(0,\:0,t0,+0,=s</span>

<span class="comment">/*</span>
<span class="comment"> * examples/graph-charpoly.C</span>
<span class="comment"> *</span>
<span class="comment"> * Copyright (C) 2005, 2007, 2010 C. Pernet</span>
<span class="comment"> *</span>
<span class="comment"> * This file is part of LinBox.</span>
<span class="comment"> *</span>
<span class="comment"> *   LinBox is free software: you can redistribute it and/or modify</span>
<span class="comment"> *   it under the terms of the GNU Lesser General Public License as</span>
<span class="comment"> *   published by the Free Software Foundation, either version 2 of</span>
<span class="comment"> *   the License, or (at your option) any later version.</span>
<span class="comment"> *</span>
<span class="comment"> *   LinBox is distributed in the hope that it will be useful,</span>
<span class="comment"> *   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> *   GNU Lesser General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> *   You should have received a copy of the GNU Lesser General Public</span>
<span class="comment"> *   License along with LinBox.  If not, see</span>
<span class="comment"> *   &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &lt;iostream&gt;</span>

<span class="preprocessor">#include &quot;linbox/blackbox/zero-one.h&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="_p_i_d-integer_8h.html" title="NO DOC.">linbox/field/PID-integer.h</a>&quot;</span>
<span class="preprocessor">#include &quot;linbox/solutions/charpoly.h&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="givaro-polynomial_8h.html" title="NO DOC.">linbox/ring/givaro-polynomial.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="methods_8h.html" title="NO DOC.">linbox/solutions/methods.h</a>&quot;</span>

<span class="keyword">using namespace </span>std;
<span class="keyword">using namespace </span>LinBox;

<span class="keyword">template</span> &lt;<span class="keyword">class</span> Field, <span class="keyword">class</span> Polynomial&gt;
<span class="keywordtype">void</span> printPolynomial(<span class="keyword">const</span> <a name="_a0"></a><a class="code" href="class_lin_box_1_1_modular_3_01uint32__t_01_4.html" title="Specialization of class Modular for uint32_t element type.">Field</a>&amp; F, <span class="keyword">const</span> Polynomial&amp; P)
{
    <span class="keywordtype">int</span> n= (int) P.size()-1;
    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0;i&lt;n;++i)
        cout&lt;&lt;P[i]&lt;&lt;<span class="stringliteral">&quot; &quot;</span>;
    cout&lt;&lt;endl;
    <span class="keywordflow">if</span> (n==1){
        cout&lt;&lt;<span class="stringliteral">&quot;X&quot;</span>;
        <span class="keywordflow">if</span> ( P[0] != 0)
            F.write(cout&lt;&lt;((P[0]&gt;0)?<span class="stringliteral">&quot;+&quot;</span>:<span class="stringliteral">&quot;&quot;</span>),P[0]);
    }
    <span class="keywordflow">else</span>{
        cout&lt;&lt;<span class="stringliteral">&quot;X^&quot;</span>&lt;&lt;n;
        <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=n-1; i&gt;1; --i)
            <span class="keywordflow">if</span> (!F.isZero(P[i]))
                F.write(cout&lt;&lt;((P[i]&gt;0)?<span class="stringliteral">&quot;+&quot;</span>:<span class="stringliteral">&quot;&quot;</span>),P[i])&lt;&lt;<span class="stringliteral">&quot;*X^&quot;</span>&lt;&lt;i;
        <span class="keywordflow">if</span> ( P[1] != 0)
            F.write(cout&lt;&lt;((P[1]&gt;0)?<span class="stringliteral">&quot;+&quot;</span>:<span class="stringliteral">&quot;&quot;</span>),P[1])&lt;&lt;<span class="stringliteral">&quot;*X&quot;</span>;
        <span class="keywordflow">if</span> ( P[0] != 0)
            F.write(cout&lt;&lt;((P[0]&gt;0)?<span class="stringliteral">&quot;+&quot;</span>:<span class="stringliteral">&quot;&quot;</span>),P[0]);
    }
}


<span class="keyword">typedef</span> <a name="_a1"></a><a class="code" href="class_lin_box_1_1_zero_one.html">ZeroOne&lt;PID_integer&gt;</a> <a class="code" href="class_lin_box_1_1_zero_one.html">Matrix</a>;
<span class="keyword">typedef</span> <a name="_a2"></a><a class="code" href="class_lin_box_1_1_giv_polynomial_ring.html" title="Polynomials.">GivPolynomialRing&lt;PID_integer,::Givaro::Dense&gt;</a> <a class="code" href="class_lin_box_1_1_giv_polynomial_ring.html" title="Polynomials.">IntPolRing</a>;

<span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
    commentator.<a name="a3"></a>getMessageClass (BRIEF_REPORT).setMaxDepth (2);
    commentator.getMessageClass (BRIEF_REPORT).setMaxDetailLevel (Commentator::LEVEL_UNIMPORTANT);


    <span class="keywordflow">if</span> (argc != 2) {
        cerr &lt;&lt; <span class="stringliteral">&quot;Usage: graph-charpoly &lt;matrix-file-in-SMS-format&gt;&quot;</span> &lt;&lt;endl;
        <span class="keywordflow">return</span> -1;
    }

    ifstream input (argv[1]);
    <span class="keywordflow">if</span> (!input) {
        cerr &lt;&lt; <span class="stringliteral">&quot;Error opening matrix file &quot;</span> &lt;&lt; argv[1] &lt;&lt; endl;
        <span class="keywordflow">return</span> -1;
    }

    <span class="comment">//UnparametricField&lt;integer&gt; ZZ;</span>
    <a name="_a4"></a><a class="code" href="class_lin_box_1_1_p_i_d__integer.html" title="Domain for integer operations.">PID_integer</a> ZZ;
    <a class="code" href="class_lin_box_1_1_zero_one.html">Matrix</a> A(ZZ);
    A.read (input);
    commentator.<a name="a5"></a><a class="code" href="class_lin_box_1_1_commentator.html#a8dd0050b1bbb1722d2c754d6c85a4ec4" title="Basic reporting.">report</a>(1, BRIEF_REPORT)&lt;&lt; <span class="stringliteral">&quot;A is &quot;</span> &lt;&lt; A.rowdim() &lt;&lt; <span class="stringliteral">&quot; by &quot;</span> &lt;&lt; A.coldim() &lt;&lt; endl;

    IntPolRing::Element c_A;

    charpoly (c_A, A, <a name="_a6"></a><a class="code" href="struct_lin_box_1_1_blackbox_specifier.html" title="BlackboxSpecifier.">Method::Blackbox</a>(<a class="code" href="struct_lin_box_1_1_method.html#a95658bcef98e7d0868b2e35d7ce03392" title="Method::Wiedemann : no doc.">Method::Wiedemann</a>( Specifier::SYMMETRIC)));

    cout&lt;&lt; <span class="stringliteral">&quot;Characteristic Polynomial is &quot;</span>;
    printPolynomial (ZZ, c_A);

    <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Tue Aug 30 2011 for linbox by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>