Math-PlanePath

 view release on metacpan or  search on metacpan

devel/chan-tree.pl  view on Meta::CPAN

    # my $n_end = $path->tree_depth_to_n_end($depth);
    # my $n_half = ($n_row + $n_end + 1)/2;
    # next unless $n >= $n_half;

    my $nk = Math::BaseCnv::cnv($n,10,$k);
    my $len = length($nk);
    last if $len > 5;
    if ($len > $prevlen) {
      print "\n";
      $prevlen = $len;
    }
    my ($x,$y) = $path->n_to_xy($n);
    my $pyth_n = $pyth->xy_to_n($x,$y);
    my $pyth_n3;
    if (defined $pyth_n) {
      $pyth_n3 = Math::BaseCnv::cnv($pyth_n,10,$k);
    }
    $pyth_n //= 'none';
    $pyth_n3 //= 'none';
    my $gcd = Math::PlanePath::GcdRationals::_gcd($x,$y);
    my $xg = $x/$gcd;
    my $yg = $y/$gcd;
    print "$n $nk  $x / $y   $gcd  reduced $xg,$yg   $pyth_n3\n";
  }
  exit 0;
}

{
  # 1 2 2 
  # 1 4 6 5 2 6 8 6 2 5 6 4 1 6 10 9 4 14 20 16 6 17 22 16 5 12 14 9

  require Math::Polynomial;
  Math::Polynomial->string_config({ ascending => 1 });

  sub make_poly_k4 {
    my ($level) = @_;
    my $pow = 4**$level;
    my $exp = 0;
    my $ret = 0;
    foreach my $coeff (1,2,2,1,2,2,1) {
      $ret += Math::Polynomial->monomial ($exp, $coeff);
      $exp += $pow;
    }
    return $ret;
  }
  print make_poly_k4(0),"\n";
  print make_poly_k4(1),"\n";

  my $poly = 1;
  foreach my $level (0 .. 4) {
    $poly *= make_poly_k4($level);
    foreach my $i (0 .. 30) {
      print " ",$poly->coeff($i);
    }
    print "\n";
  }
  exit 0;
}

{
  # children formulas
  foreach my $k (3 .. 8) {
    my $half_ceil = int(($k+1) / 2);
    foreach my $digit (0 .. $k-1) {
      my $c1 = ($digit < $half_ceil ? $digit+1 : $k-$digit);
      my $c0 = ($digit <= $half_ceil ? $digit : $k-$digit+1);
      my $c2 = ($digit < $half_ceil-1 ? $digit+2 : $k-$digit-1);
      print "${c1}x + ${c0}y / ${c2}x + ${c1}y\n";
    }
    print "\n";
  }
  exit 0;
}

{
 # 1 2 3 2 1 4 7 8 5 2 7 12 13 8 3 8 13 12 7 2 5 8 7 4 1 6 11 14 9 4 15

  require Math::Polynomial;
  Math::Polynomial->string_config({ ascending => 1 });

  sub make_poly_k5 {
    my ($level) = @_;
    my $pow = 5**$level;
    my $exp = 0;
    my $ret = 0;
    foreach my $coeff (1,2,3,2,1,2,3,2,1) {
      $ret += Math::Polynomial->monomial ($exp, $coeff);
      $exp += $pow;
    }
    return $ret;
  }
  print make_poly_k5(0),"\n";
  print make_poly_k5(1),"\n";

  my $poly = 1;
  foreach my $level (0 .. 4) {
    $poly *= make_poly_k5($level);
    foreach my $i (0 .. 30) {
      print " ",$poly->coeff($i);
    }
    print "\n";
  }
  # (1 + 2*x + 3*x^2 + 2*x^3 + x^4 + 2*x^5 + 3*x^6 + 2*x^7 + x^8)
  # * (1 + 2*x^5 + 3*x^10 + 2*x^15 + x^20 + 2*x^25 + 3*x^30 + 2*x^35 + x^40)
  # * (1 + 2*x^(25*1) + 3*x^(25*2) + 2*x^(25*3) + x^(25*4) + 2*x^(25*5) + 3*x^(25*6) + 2*x^(25*7) + x^(25*8))
  exit 0;
}



( run in 0.742 second using v1.01-cache-2.11-cpan-df04353d9ac )