Result:
found more than 658 distributions - search limited to the first 2001 files matching your query ( run in 0.703 )


Math-Complex

 view release on metacpan or  search on metacpan

lib/Math/Complex.pm  view on Meta::CPAN

between this form and the cartesian form C<a + bi> is immediate:

	a = rho * cos(theta)
	b = rho * sin(theta)

which is also expressed by this formula:

	z = rho * exp(i * theta) = rho * (cos theta + i * sin theta)

In other words, it's the projection of the vector onto the I<x> and I<y>
axes. Mathematicians call I<rho> the I<norm> or I<modulus> and I<theta>

 view all matches for this distribution


Math-ConvexHull

 view release on metacpan or  search on metacpan

lib/Math/ConvexHull.pm  view on Meta::CPAN

implementation in the German translation of
Orwant et al, "Mastering Algorithms with Perl". Their code reads better than
mine, so if you looked at the module sources and don't understand
what's going on, I suggest you have a look at the book.

In early 2011, much of the module was rewritten to use the formulation of
the algorithm that was shown on the Wikipedia article on Graham's scan at
the time. This takes care of issues with including collinear points in the
hull.

L<http://en.wikipedia.org/wiki/Graham_scan>

 view all matches for this distribution


Math-Derivative

 view release on metacpan or  search on metacpan

lib/Math/Derivative.pm  view on Meta::CPAN


Take the references to two arrays containing the x and y ordinates of
the data, and return an array of approximate first derivatives at the
given x ordinates, using the forward difference approximation.

The last term is actually formed using a backward difference formula,
there being no array item to subtract from at the end of the array.
If you want to use derivatives strictly formed from the forward
difference formula, use only the values from [0 .. #y-1], e.g.:

    @dydx = (forwarddiff(\@x, \@y))[0 .. $#y-1];

or, more simply,

lib/Math/Derivative.pm  view on Meta::CPAN

given x ordinates.

The algorithm used three data points to calculate the derivative, except
at the end points, where by necessity the forward difference algorithm
is used instead. If you want to use derivatives strictly formed from
the central difference formula, use only the values from [1 .. #y-1],
e.g.:

    @dydx = (centraldiff(\@x, \@y))[1 .. $#y-1];

=cut

 view all matches for this distribution


Math-DyckWords

 view release on metacpan or  search on metacpan

lib/Math/DyckWords.pm  view on Meta::CPAN

    (())()
    (()())

There is also a relationship between Dyck words and Catalan numbers.
Catalan numbers have many applications in combinatorics and consists
of a sequence of ever increasing integers following the formula:

    (2n)!/(n!(n+1)!)

The first few numbers in the Catalan sequence are:

lib/Math/DyckWords.pm  view on Meta::CPAN


=over

=item catalan_number( $n )

Using the formula - (2n)!/(n!(n+1)!) - this function returns the
corresponding number $n from the Catalan sequence.

=back

=cut

 view all matches for this distribution


Math-EMA

 view release on metacpan or  search on metacpan

lib/Math/EMA.pm  view on Meta::CPAN

  $avg->add($some_value);
  my $ema=$avg->ema;

=head1 DESCRIPTION

This module computes an exponential moving average by the following formula

  avg(n+1) = (1 - alpha) * new_value + alpha * avg(n)

where alpha is a number between 0 and 1.

 view all matches for this distribution


Math-Expr-LATEST

 view release on metacpan or  search on metacpan

Expr/FormulaDB.pm  view on Meta::CPAN

#!/usr/bin/perl 

#  FormulaDB.pm - A db of formulas and there properties
#  (c) Copyright 1998 Hakan Ardo <hakan@debian.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or

Expr/FormulaDB.pm  view on Meta::CPAN

#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

=head1 NAME

  Math::Expr::FormulaDB - A db of formulas and there properties

=head1 SYNOPSIS

  require Math::Expr::FormulaDB;
  $db=new Math::Expr::FormulaDB($file);

 view all matches for this distribution


Math-Expression

 view release on metacpan or  search on metacpan

Expression.pm  view on Meta::CPAN

Error messages may be via a user provided function.
This is not designed for high computation use.

=head1 EXAMPLE

Shipping cost depends on item price by some arbitrary formula. The VAT amount can also
vary depending on political edict. Rather than nail these formula into the application code the
formula are obtained at run time from some configuration source. These formula are
entered by a non technical manager and are thus not to be trusted.

    use Math::Expression;
    my $ArithEnv = new Math::Expression;

Expression.pm  view on Meta::CPAN


# Price of what you are selling, set the price variable:
    my $price = 100;
    $ArithEnv->VarSetScalar('Price', $price);

# Obtain VAT & Shipping using the configured formula:
    my $VatTax = $ArithEnv->ParseToScalar($VatFormula);
    my $Shipping  = $ArithEnv->ParseToScalar($ShippingFormula);

    say "Price=$price VatTax=$VatTax Shipping=$Shipping";

# If these will be run many times, parse the formula once:

    my $VatExpr = $ArithEnv->Parse($VatFormula);
    my $ShipExpr = $ArithEnv->Parse($ShippingFormula);

# Evaluate it with the current price many times:

 view all matches for this distribution


Math-Formula

 view release on metacpan or  search on metacpan

lib/Math/Formula.pm  view on Meta::CPAN


use warnings;
use strict;
use utf8;

use Log::Report 'math-formula';
use Scalar::Util qw/blessed/;

use Math::Formula::Token;
use Math::Formula::Type;

lib/Math/Formula.pm  view on Meta::CPAN

	(bless {}, $class)->init(\%self);
}

sub init($)
{	my ($self, $args) = @_;
	my $name    = $self->{MSBE_name} = $args->{_name} or panic "every formular requires a name";
	my $expr    = $args->{_expr} or panic "every formular requires an expression";
	my $returns = $self->{MSBE_returns} = $args->{returns};

	if(ref $expr eq 'SCALAR')
	{	$expr = MF::STRING->new(undef, $$expr);
	}

 view all matches for this distribution


Math-Fraction-Egyptian

 view release on metacpan or  search on metacpan

example/2n-table.txt  view on Meta::CPAN


The first, and second methods, are recorded in the Kahun Papyrus and the Rhind
Mathematical Papyrus. Both texts solved arithmetic progression problems by
using rational number differences. Egyptian fraction series were used to write
final answers. Arithmetic progressions, an algebra topic that followed
interesting formulas, will not be discussed. The second method, an arithmetic
topic, 2/n tables, listing optimized unit fraction series, will be discussed
in terms of a likely ancient unifying theme.

Overly analytical views of possible 2/n table methods, especially potential
2/35, 2/91 and 2/95 conversion methods have been suggested by scholars for

 view all matches for this distribution


Math-FresnelZone

 view release on metacpan or  search on metacpan

FresnelZone.pm  view on Meta::CPAN


None by default. You can export any of the 3 functions as in the synopsis example.

=head2 VARIABLES

These variables are used when using miles/feet instead of kilometers/meters to modify the input for the formula and the output for the user:

   $Math::FresnelZone::KILOMETERS_IN_A_MILE  (Default is 1.609344)
   $Math::FresnelZone::FEET_IN_A_METER (Defualt is 3.280839)

Feel free to change them if you need more or less than six decimal places and/or want really inaccurate results :)

=head1 SEE ALSO

To find out more about the fresnel zone (pronounced fray-NELL) you can google the man who this formula/zone is named after to learn more: Augustin Jean Fresnel.

Mr. Fresnel was a French physicist who supported the wave theory of light, investigated polarized light, 
and developed a compound lens for use in lighthouses (IE the "Fresnel lens") (1788-1827).

Also googling the phrase "Fresnel Zone" turns up some interesting glossary refernces to what the fresnel zone is.

Here is a link to an image illustrating what a fresnel zone is and the formula:
L<http://drmuey.com/images/fresnelzone.jpg>

=head1 AUTHOR

Daniel Muey, L<http://drmuey.com/cpan_contact.pl> 

 view all matches for this distribution


Math-GF

 view release on metacpan or  search on metacpan

docs/index.md  view on Meta::CPAN


Now that we have a trick, we still have to find out one last way to
actually find an irreducible polynomial of the desired order \\(n\\) over
the field we are extending. There are some results about it:

- they actually exist! There is someone that calculated a formula to count
  them, which also implies that fields of order \\(p^n\\) exists, of
  course! See [this question][irred-count] for further information;
- there always exist *monic* ones, i.e. where the coefficient for the
  highest power of \\(x\\) is \\(1\\) (which simplifies the division and
  the rest calculation);

 view all matches for this distribution


Math-GSL

 view release on metacpan or  search on metacpan

lib/Math/GSL/Histogram.pm  view on Meta::CPAN


=item C<gsl_histogram_pdf_init($p, $h)> - This function initializes the probability distribution $p with the contents of the histogram $h. If any of the bins of $h are negative then the error handler is invoked with an error code of $GSL_EDOM because...

=item C<gsl_histogram_pdf_free($p)> - This function frees the probability distribution function $p and all of the memory associated with it.

=item C<gsl_histogram_pdf_sample($p, $r)> -     This function uses $r, a uniform random number between zero and one, to compute a single random sample from the probability distribution $p. The algorithm used to compute the sample s is given by the fo...

=back

=head1 EXAMPLES

 view all matches for this distribution


Math-Geometry-Delaunay

 view release on metacpan or  search on metacpan

src/triangle.c  view on Meta::CPAN

/*    at a linear rate (constant time per triangle) after the initial        */
/*    triangulation is formed.  There may be pathological cases where        */
/*    quadratic time is required, but these never arise in practice.         */
/*                                                                           */
/*  The geometric predicates (circumcenter calculations, segment             */
/*    intersection formulae, etc.) appear in my "Lecture Notes on Geometric  */
/*    Robustness" at http://www.cs.berkeley.edu/~jrs/mesh .                  */
/*                                                                           */
/*  If you make any improvements to this code, please please please let me   */
/*    know, so that I may obtain the improvements.  Even if you don't change */
/*    the code, I'd still love to hear what it's being used for.             */

src/triangle.c  view on Meta::CPAN


  /* Find the other three segment endpoints. */
  apex(*splittri, endpoint1);
  org(*splittri, torg);
  dest(*splittri, tdest);
  /* Segment intersection formulae; see the Antonio reference. */
  tx = tdest[0] - torg[0];
  ty = tdest[1] - torg[1];
  ex = endpoint2[0] - endpoint1[0];
  ey = endpoint2[1] - endpoint1[1];
  etx = torg[0] - endpoint2[0];

 view all matches for this distribution


Math-Geometry-IntersectionArea

 view release on metacpan or  search on metacpan

lib/Math/Geometry/IntersectionArea.pm  view on Meta::CPAN

    # solving the following cuadratic equation:
    #
    #   norm(a + alfa * ab) = d
    #
    #
    # The coeficientes c2, c1, c0 are deduced from the formula
    # above such that:
    #
    #   c2 * alfa**2 + 2 * c1 * alfa + c0 = 0
    #
    # And then the clasical formula for quadratic equation solved is
    # used:
    #
    #   alfa0 = 1/c2 + (-$c1 + sqrt($c1*$c1 - 4 * $c0 * $c2))
    #   alfa1 = 1/c2 + (-$c1 - sqrt($c1*$c1 - 4 * $c0 * $c2))

 view all matches for this distribution


Math-Geometry-Planar-Offset

 view release on metacpan or  search on metacpan

lib/Math/Geometry/Planar/Offset.pm  view on Meta::CPAN

		# happens on the line segments, we are here with
		# the x and y coordinates of the intersection of the two lines.
		## $debug and printf ("intersection: %6.0f,%6.0f\n",$x_int, $y_int);

		# Let's find the time of intersect.
		# distance  formula with adjustment for speed
		$time = sqrt( ($x_int - $points->[$n][0])**2 + ($y_int - $points->[$n][1])**2 ) / $bis_scale[$n];
		if( (abs($time) < $first_time) )
			# && ( $time / abs($time)== $offset / abs($offset) ) )
			{
			# note that none of the times loaded here have a sign

 view all matches for this distribution


Math-Geometry-Planar

 view release on metacpan or  search on metacpan

Planar.pm  view on Meta::CPAN

    return 1;
  }
}
################################################################################
#
# a counter clockwise rotation over an angle a is given by the formula
#
#  / x2 \      /  cos(a)  -sin(a) \  / x1 \
#  |    |   =  |                  |  |    |
#  \ y2 /      \  sin(a)   cos(a) /  \ y1 /
#

 view all matches for this distribution


Math-LOESS

 view release on metacpan or  search on metacpan

lib/Math/LOESS/Prediction.pm  view on Meta::CPAN

=head2 df

Degrees of freedom of the loess fit.

It is used with the t-distribution to compute pointwise confidence
intervals for the evaluated surface. It is obtained using the formula
C<(one_delta ** 2) / two_delta>

=head1 METHODS

=head2 confidence

 view all matches for this distribution


Math-Lsoda

 view release on metacpan or  search on metacpan

opkda1.f  view on Meta::CPAN

C
C  The computed values in DKY are gotten by interpolation using the
C  Nordsieck history array YH.  This array corresponds uniquely to a
C  vector-valued polynomial of degree NQCUR or less, and DKY is set
C  to the K-th derivative of this polynomial at T.
C  The formula for DKY is:
C               q
C   DKY(i)  =  sum  c(j,K) * (T - tn)**(j-K) * h**(-j) * YH(i,j+1)
C              j=K
C  where  c(j,K) = j*(j-1)*...*(j-K+1), q = NQCUR, tn = TCUR, h = HCUR.
C  The quantities  nq = NQCUR, l = nq+1, N = NEQ, tn, and h are

 view all matches for this distribution


Math-MPFR

 view release on metacpan or  search on metacpan

MPFR.pod  view on Meta::CPAN

    is less than the exact value.

   $inex = Rmpfr_const_pi($rop, $rnd);
    Set $rop to the value of Pi rounded to the direction $rnd
    with the precision of $rop. This function uses the Borwein,
    Borwein, Plouffe formula which directly gives the expansion
    of Pi in base 16.
    Return zero if $rop is exact, a positive value if $rop is
    larger than the exact value, or a negative value if $rop
    is less than the exact value.

 view all matches for this distribution


Math-MatrixLUP

 view release on metacpan or  search on metacpan

examples/faulhaber_coefficients.pl  view on Meta::CPAN

#!/usr/bin/perl

# Compute the Faulhaber triangle of coffiecients.

# See also:
#   https://en.wikipedia.org/wiki/Faulhaber's_formula
#   https://en.wikipedia.org/wiki/Vandermonde_matrix

use 5.014;
use lib qw(../lib);
use experimental qw(signatures);

 view all matches for this distribution


Math-MatrixReal

 view release on metacpan or  search on metacpan

lib/Math/MatrixReal.pm  view on Meta::CPAN

rows and columns.
Multiply the determinant by (-1)^(i+j), where i is the row index,
and j is the column index. 
Replace the given element with this value.

The cofactor matrix can be used to find the inverse of the matrix. One formula for the
inverse of a matrix is the cofactor matrix transposed divided by the original
determinant of the matrix. 

The following two inverses should be exactly the same:

lib/Math/MatrixReal.pm  view on Meta::CPAN

"x" and "y", respectively, and the "C<e[i]>" are unity vectors (i.e.,
vectors with a length equal to one) with a one in row "i" and zero's
elsewhere (this means that you have numbers and vectors as elements
in this matrix!).

This determinant evaluates to the rather simple formula

  z[1] = x[2] * y[3] - x[3] * y[2]
  z[2] = x[3] * y[1] - x[1] * y[3]
  z[3] = x[1] * y[2] - x[2] * y[1]

lib/Math/MatrixReal.pm  view on Meta::CPAN


The difference between the three methods is the following:

In the "Global Step Method" ("GSM"), the new vector "C<x(t+1)>"
(called "y" here) is calculated from the vector "C<x(t)>"
(called "x" here) according to the formula:

  y[i] =
  ( b[i]
      - ( a[i,1] x[1] + ... + a[i,i-1] x[i-1] +
          a[i,i+1] x[i+1] + ... + a[i,n] x[n] )

lib/Math/MatrixReal.pm  view on Meta::CPAN


In the "Relaxation method" ("RM"), the components of the vector
"C<x(t+1)>" are calculated by "mixing" old and new value (like
cold and hot water), and the weight "C<$weight>" determines the
"aperture" of both the "hot water tap" as well as of the "cold
water tap", according to the formula:

  y[i] =
  ( b[i]
      - ( a[i,1] y[1] + ... + a[i,i-1] y[i-1] +  # note the "y[]"!
          a[i,i+1] x[i+1] + ... + a[i,n] x[n] )  # note the "x[]"!

 view all matches for this distribution


Math-NV

 view release on metacpan or  search on metacpan

NV.pm  view on Meta::CPAN


$Math::NV::no_warn = 0; # set to 1 to disable warning about non-string argument
                        # set to 2 to disable output of the 2 non-matching values
                        # set to 3 to disable both of the above

# %_itsa is utilised in the formulation of the diagnostic message
# when it's detected that the provided arg is not a string.

my %_itsa = (
  1 => 'UV',
  2 => 'IV',

 view all matches for this distribution


Math-NumSeq

 view release on metacpan or  search on metacpan

devel/balanced-binary.pl  view on Meta::CPAN

  print "$prev\n";
  exit 0;
}

{
  # formula

  require Math::NumSeq::Catalan;
  my $seq = Math::NumSeq::Catalan->new;

  my $cumul = 0;
  foreach (1 .. 20) {
    my ($i, $value) = $seq->next;

    my $formula = 0;
    foreach my $k (1 .. $i-1) {
      $formula += $seq->ith($i-$k)*$k + $seq->ith($k)
    }
    print "$i value=$value formula=$formula\n";
    $cumul += $value;
  }
  exit 0;
}

 view all matches for this distribution


Math-NumberCruncher

 view release on metacpan or  search on metacpan

NumberCruncher.pod  view on Meta::CPAN


Implementation of Einstein's E=MC**2.  Given either energy or mass, the function returns the other. When passing mass, the value must be preceeded by a "m," which may be either upper or lower case.  When passing energy, the value must be preceeded by...

=head2 $force = B<Math::NumberCruncher::FMA>( "m97", "a53" [, $decimal_places] );

Implementation of the stadard force = mass * acceleration formula.  Given two of the three variables (i.e., mass and force, mass and acceleration, or acceleration and force), the function returns the third.  When passing the values, mass must be prec...

=head2 $predicted = B<Math::NumberCruncher::Predict>( $slope, $y_intercept, $proposed_x [, $decimal_places] );

Useful for predicting values based on data trends, as calculated by BestFit(). Given the slope and y-intercept, and a proposed value of x, returns corresponding y.

=head2 $area = B<Math::NumberCruncher::TriangleHeron>( $a, $b, $c [, $decimal_places] );

Calculates the area of a triangle, using Heron's formula.  TriangleHeron() can be passed either the lengths of the three sides of the triangle, or the (x,y) coordinates of the three verticies.

=head2 $perimeter = B<Math::NumberCruncher::PolygonPerimeter>( $x0,$y0, $x1,$y1, $x2,$y2, ... [, p$decimal_places]);

Calculates the length of the perimeter of a given polygon. The final argument specifies the number of decimal places you want. To specify a number other than the default (see above), the number must be preceeded by the letter "p". For example: Math::...

NumberCruncher.pod  view on Meta::CPAN


Calculates the surface area of a sphere, given the radius.

=head2 $years = B<Math::NumberCruncher::RuleOf72>( $interest_rate [, $decimal_places] );

A very simple financial formula. It calculates how many years, at a given interest rate, it will take to double your money, provided that the money and all interest is left in the account.

=head2 $volume = B<Math::NumberCruncher::CylinderVolume>( $radius, $height [, $decimal_places] );

Calculates the volume of a cylinder given the radius and the height.

 view all matches for this distribution


Math-OEIS

 view release on metacpan or  search on metacpan

examples/grep-not-in-oeis.pl  view on Meta::CPAN

# Sequences which match but you know are false (become different later, only
# a middle match, close but not quite what you want, etc) can be excluded by
# further "not" lines like
#
#     # not in OEIS: 17238, 12783, 4839, 589
#     # not A123456 as its formula is different after 200 terms
#     # not A000006 which begins differently
#
# This program is an example of using Math::OEIS::Grep in a mechanical way.
# The "not A123456" lines become its "exclude_list".  Perhaps some
# additional hints or exclusions will be possible in the future, eg. values

examples/grep-not-in-oeis.pl  view on Meta::CPAN

      }
    }

    {
      # Notice duplicate searches, which can be due to too much cut and
      # paste, or sometimes an unnoticed relationship between formulas etc.
      # Those on immediately following lines are ok, being some subset
      # search.
      my $str = join(',',@values);
      foreach my $seen (reverse @seen) {  # reverse for most recent first
        my $seen_str = $seen->{'str'};

 view all matches for this distribution


Math-Pari

 view release on metacpan or  search on metacpan

patches/diff_add_gnuplotAdd  view on Meta::CPAN

+} udft_entry;
+
+typedef struct {
+  /** Constants: **/
+
+  /* (Fixed) number of formulae implemented for gray index to RGB
+   * mapping in color.c.  Usage: somewhere in `set' command to check
+   * that each of the below-given formula R,G,B are lower than this
+   * value. */
+  int colorFormulae;
+
+  /** Values that can be changed by `set' and shown by `show' commands: **/
+
+  /* can be SMPAL_COLOR_MODE_GRAY or SMPAL_COLOR_MODE_RGB */
+  palette_color_mode colorMode;
+  /* mapping formulae for SMPAL_COLOR_MODE_RGB */
+  int formulaR, formulaG, formulaB;
+  char positive;		/* positive or negative figure */
+
+  /* Now the variables that contain the discrete approximation of the
+   * desired palette of smooth colours as created by make_palette in
+   * pm3d.c.  This is then passed into terminal's make_palette, who

patches/diff_add_gnuplotAdd  view on Meta::CPAN

+  int use_maxcolors;
+  /* Number of colours used for the discrete palette. Equals to the
+   * result from term->make_palette(NULL), or restricted by
+   * use_maxcolor.  Used by: pm, gif. Unused by: PostScript */
+  int colors;
+  /* Table of RGB triplets resulted from applying the formulae. Used
+   * in the 2nd call to term->make_palette for a terminal with
+   * discrete colours. Unused by PostScript which has calculates them
+   * analytically. */
+  rgb_color *color;
+
+  /** Variables used by some terminals **/
+  
+  /* Option unique for output to PostScript file.  By default,
+   * ps_allcF=0 and only the 3 selected rgb color formulae are written
+   * into the header preceding pm3d map in the file.  If ps_allcF is
+   * non-zero, then print there all color formulae, so that it is easy
+   * to play with choosing manually any color scheme in the PS file
+   * (see the definition of "/g"). Like that you can get the
+   * Rosenbrock multiplot figure on my gnuplot.html#pm3d demo page.
+   * Note: this option is used by all terminals of the postscript
+   * family, i.e. postscript, pslatex, epslatex, so it will not be

 view all matches for this distribution


Math-PlanePath-Toothpick

 view release on metacpan or  search on metacpan

devel/one-of-eight.pl  view on Meta::CPAN

    my $calc = (16*4**$k + 24*$k - 7) / 9;

    my $delta = $n - $prev_n;
    my $d2 = Math::BaseCnv::cnv($delta,10,2);

    printf "%5d path=%8d formula=%8d cells=%8d %20s\n",
      $depth, $pn, $calc, $n, $n2;
    # printf "%5d %8d  %20s\n", $depth, $delta, $d2;
    $prev_n = $n;
  }
  exit 0;

 view all matches for this distribution


Math-PlanePath

 view release on metacpan or  search on metacpan

devel/c-curve.pl  view on Meta::CPAN

  }
}

{
  my @sdir = (2,2,0,-2, -2,-2,0,2);
  sub s0_by_formula {
    my ($k) = @_;
    {
      my $h = int($k/2);
      return 2**$k/4 + $sdir[$k%8]*2**$h/4;
    }

devel/c-curve.pl  view on Meta::CPAN

              + (Math::Complex->new(1,-1)**$k * Math::Complex->new(1,-1)
                 + Math::Complex->new(1,1) **$k * Math::Complex->new(1,1)) / 4);
    }
  }
  my @s1dir = (0,2,2,2, 0,-2,-2,-2);
  sub s1_by_formula {
    my ($k) = @_;
    my $h = int($k/2);
    return 2**$k/4 + $sdir[($k-2)%8]*2**$h/4;
  }
  my @s2dir = (0,2,2,2, 0,-2,-2,-2);
  sub s2_by_formula {
    my ($k) = @_;
    my $h = int($k/2);
    return 2**$k/4 + $sdir[($k-4)%8]*2**$h/4;
  }
  sub s3_by_formula {
    my ($k) = @_;
    my $h = int($k/2);
    return 2**$k/4 + $sdir[($k-6)%8]*2**$h/4;
  }
#  print "  1,  1,  1,  1,  2,  6, 16, 36, 72,136,256,496,992,2016,4096,8256,16512,32896,65536,\n";  # M0
#  print "  0,  1,  2,  3,  4,  6, 12, 28, 64,136,272,528,1024,2016,4032,8128,16384,32896,65792,\n"; # M1
#  print "  0,  0,  1,  3,  6, 10, 16, 28, 56,120,256,528,1056,2080,4096,8128,16256,32640,65536,\n"; # M2
  print "  0,  0,  0,  1,  4, 10, 20, 36, 64,120,240,496,1024,2080,4160,8256,16384,32640,65280,\n"; # M3
  foreach my $k (0 .. 17) {
    printf "%3d,", s3_by_formula($k);
  }
  exit 0;
}


devel/c-curve.pl  view on Meta::CPAN

  }
  exit 0;
}

{
  # right boundary formula vs recurrence
  # R[k] = 2*R[k-1] + R[k-2] - 4*R[k-3] + 2*R[k-4]
  #
  # R[2k]   = 4*R[2k-2] - 5*R[2k-4] + 2*R[2k-6]
  # R[2k+1] = 4*R[2k-1] - 5*R[2k-3] + 2*R[2k-5]

  my $R;
  $R = sub {
    my ($k) = @_;
    if ($k < 4) { return R_formula($k); }
    return (2*$R->($k-4)
            - 4*$R->($k-3)
            + $R->($k-2)
            + 2*$R->($k-1));
  };

devel/c-curve.pl  view on Meta::CPAN

  $R = Memoize::memoize($R);

  my $R2;
  $R2 = sub {
    my ($k) = @_;
    if ($k < 3) { return R_formula(2*$k); }
    return (2*$R2->($k-3)
            - 5*$R2->($k-2)
            + 4*$R2->($k-1));
  };
  require Memoize;
  $R2 = Memoize::memoize($R2);

  my $R2P1;
  $R2P1 = sub {
    my ($k) = @_;
    if ($k < 3) { return R_formula(2*$k+1); }
    return (2*$R2P1->($k-3)
            - 5*$R2P1->($k-2)
            + 4*$R2P1->($k-1));
  };
  require Memoize;
  $R2P1 = Memoize::memoize($R2P1);

  foreach my $k (0 .. 50) {
    # my $want = R_formula($k);
    # print "$k  $want  ",$R->($k),"\n";
    my $want = R_formula(2*$k);
    print "$k  $want  ",$R2->($k),"\n";
  }
  exit 0;
}



{
  # right outer boundary with sqrt(2)

  sub S_formula {
    my ($h) = @_;
    return 2**$h;
  };
  sub Z_formula {
    my ($h) = @_;
    return 2*2**$h - 2;
  };
  my $S_cum = sub {   # sum S[0] .. S[h] inclusive
    my ($h) = @_;

devel/c-curve.pl  view on Meta::CPAN

    my ($k) = @_;
    my ($h, $rem) = Math::PlanePath::_divrem($k,2);
    if ($rem) {
      return 2*$S_cum->($h);
    } else {
      return 2*$S_cum->($h-1) + S_formula($h);
    }
  };
  my $Z_inR = sub {
    my ($k) = @_;
    my ($h, $rem) = Math::PlanePath::_divrem($k,2);
    if ($rem) {
      return 2*$Z_cum->($h-1) + Z_formula($h);
    } else {
      return 2*$Z_cum->($h-1);
    }
  };
  my $R_bySZ = sub {

devel/c-curve.pl  view on Meta::CPAN


  {
    my $total = 0;
    foreach my $h (0 .. 10) {
      $total == $S_cum->($h-1) or die;
      $total += S_formula($h);
    }
  }
  {
    my $total = 0;
    foreach my $h (0 .. 10) {
      $total == $Z_cum->($h-1) or die;
      $total += Z_formula($h);
    }
  }
  # {
  #   print $S_cum->(-1),"\n";
  #   foreach my $h (0 .. 10) {
  #     print "+ ",S_formula($h), " = ",$S_cum->($h),"\n";
  #   }
  # }
  {
    foreach my $k (0 .. 10) {
      my $s = $S_inR->($k);
      my $z = $S_inR->($k);
      my $rby = $R_bySZ->($k);
      my $rformula = R_formula($k);
      # print "$k  $s + $z = $rby   rf=$rformula\n";
      $rby == $rformula or die "$k $rby $rformula";
    }
  }

  {
    foreach my $k (0 .. 100) {

devel/c-curve.pl  view on Meta::CPAN


}
{
  # right outer boundary

  sub R_formula {
    my ($k) = @_;
    my $h = int($k/2);

    return ($k & 1
            ? 10*2**$h - 2*$k - 6   # yes

devel/c-curve.pl  view on Meta::CPAN

    if ($k == 1) { return 2; }
    return 2*$R_recurrence->($k-2) + 2*$k-2;
  };

  for (my $k = 0; $k < 15; $k++) {
    print R_formula($k),", ";
  }
  print "\n";

  require MyOEIS;
  my $path = Math::PlanePath::CCurve->new;

devel/c-curve.pl  view on Meta::CPAN

    # my $u2 = $U2->($k);
    # my $u_lr = $U_from_LsubR->($k);
    # my $v = $V->($k);
    my ($s, $z) = path_S_and_Z($path, $n_end);
    my $r = $s + $z + 1;
    my $rformula = R_formula($k);
    my $drformula = $r - $rformula;
    # next unless $k & 1;
    print "$k $p  $s $z $r   $srec $zrec $rszrec $rrec $rformula  small by=$drformula\n";
  }
  exit 0;

  sub path_S_and_Z {
    my ($path, $n_end) = @_;

 view all matches for this distribution


( run in 0.703 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )