[28512] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9876 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 21 21:05:53 2006

Date: Sat, 21 Oct 2006 18:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 21 Oct 2006     Volume: 10 Number: 9876

Today's topics:
        A Comparison Of Dynamic and Static Languiges atbusbook@aol.com
    Re: A Comparison Of Dynamic and Static Languiges <nospam@nosite.zzz>
    Re: A Comparison Of Dynamic and Static Languiges <s-mar@nospam.nospam>
    Re: A Comparison Of Dynamic and Static Languiges <ptmcg@austin.rr._bogus_.com>
    Re: A Comparison Of Dynamic and Static Languiges <sturlamolden@yahoo.no>
    Re: avoid multiple script startup overhead <tzz@lifelogs.com>
    Re: Matching umlauts <rvtol+news@isolution.nl>
    Re: Reverse algorithm with tangent <jl_post@hotmail.com>
    Re: Reverse algorithm with tangent <bik.mido@tiscalinet.it>
    Re: Reverse algorithm with tangent <hjp-usenet2@hjp.at>
    Re: Reverse algorithm with tangent <bart@nijlen.com>
    Re: Reverse algorithm with tangent <hjp-usenet2@hjp.at>
    Re: Reverse algorithm with tangent <nospam-abuse@ilyaz.org>
    Re: Reverse algorithm with tangent <bik.mido@tiscalinet.it>
    Re: Reverse algorithm with tangent <hjp-usenet2@hjp.at>
    Re: Sorting Data in Two Columns <alison@logicsaysNOSPAM.com>
    Re: Sorting Data in Two Columns <alison@logicsaysNOSPAM.com>
    Re: unable to calculate large file size <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 21 Oct 2006 11:28:04 -0700
From: atbusbook@aol.com
Subject: A Comparison Of Dynamic and Static Languiges
Message-Id: <1161455284.563900.320430@m7g2000cwm.googlegroups.com>

I'm doing a report on the speed of develipment and executionin varius
programing langiuiges. write code for all these tasks in the languige
of your choise if intrestied send code to atbusbook@aol.com.

Task 1:
  write a program that prints how many times you repeat all words in a
file passed as a comand line
  paramiter and from STDIN. with the output format being "\"%s\" word
repeated %i times\n"
Task 2:
  write a comand line rpn calculator that has a syntax like forth with
only floats; also it must have these and
  only these operations +, -, *, /, ., .s, rot, dup, swap, pick, roll.
 . and .s are pop print and .s print stack in this
  with a new line after each item and the top of the stack at the
bottom.

compiler info

c#: mono 1.1.13.7
perl: perl 5.8.8
python: python 2.4.2
ruby: ruby 1.8.4



------------------------------

Date: Sat, 21 Oct 2006 11:37:06 -0700
From: Paul Lutus <nospam@nosite.zzz>
Subject: Re: A Comparison Of Dynamic and Static Languiges
Message-Id: <12jkq6k867mls6f@corp.supernews.com>

atbusbook@aol.com wrote:

> I'm doing a report on the speed of develipment and executionin varius
> programing langiuiges. write code for all these tasks in the languige
> of your choise if intrestied send code to atbusbook@aol.com.

What you should be doing is learning basic literacy.

Life works like this:

1. Write your magnum opus article, become famous, retire to a Greek island.

2. But first, learn how to assemble paragraphs into articles.

3. But first, learn how to assemble sentences into paragraphs.

4. But first, learn how to assemble words into sentences.

5. But first, learn how to assemble letters into words.

Start at the bottom, work to the top. Whatever you do, do not presume to
start at the top.

Also, don't post your homework assignment word-for-word. It makes you look
craven and inexperienced.

-- 
Paul Lutus
http://www.arachnoid.com


------------------------------

Date: Sat, 21 Oct 2006 14:36:05 -0400
From: "Scott M." <s-mar@nospam.nospam>
Subject: Re: A Comparison Of Dynamic and Static Languiges
Message-Id: <eY$5v#T9GHA.2288@TK2MSFTNGP05.phx.gbl>

Perhaps you should do your own work so you'll understand the concept and 
learn something?

Also, widely posting your real (unaltered) email address in forums like this 
is a sure way to get noticed by spammers.

Good luck.

<atbusbook@aol.com> wrote in message 
news:1161455284.563900.320430@m7g2000cwm.googlegroups.com...
> I'm doing a report on the speed of develipment and executionin varius
> programing langiuiges. write code for all these tasks in the languige
> of your choise if intrestied send code to atbusbook@aol.com.
>
> Task 1:
>  write a program that prints how many times you repeat all words in a
> file passed as a comand line
>  paramiter and from STDIN. with the output format being "\"%s\" word
> repeated %i times\n"
> Task 2:
>  write a comand line rpn calculator that has a syntax like forth with
> only floats; also it must have these and
>  only these operations +, -, *, /, ., .s, rot, dup, swap, pick, roll.
> . and .s are pop print and .s print stack in this
>  with a new line after each item and the top of the stack at the
> bottom.
>
> compiler info
>
> c#: mono 1.1.13.7
> perl: perl 5.8.8
> python: python 2.4.2
> ruby: ruby 1.8.4
> 




------------------------------

Date: Sat, 21 Oct 2006 18:38:32 GMT
From: "Paul McGuire" <ptmcg@austin.rr._bogus_.com>
Subject: Re: A Comparison Of Dynamic and Static Languiges
Message-Id: <IOt_g.294$GR2.283@tornado.texas.rr.com>

<atbusbook@aol.com> wrote in message 
news:1161455284.563900.320430@m7g2000cwm.googlegroups.com...
> I'm doing a report on the speed of develipment and executionin varius
> programing langiuiges. write code for all these tasks in the languige
> of your choise if intrestied send code to atbusbook@aol.com.
>
> Task 1:
>  write a program that prints how many times you repeat all words in a
> file passed as a comand line
>  paramiter and from STDIN. with the output format being "\"%s\" word
> repeated %i times\n"
> Task 2:
>  write a comand line rpn calculator that has a syntax like forth with
> only floats; also it must have these and
>  only these operations +, -, *, /, ., .s, rot, dup, swap, pick, roll.
> . and .s are pop print and .s print stack in this
>  with a new line after each item and the top of the stack at the
> bottom.
>
> compiler info
>
> c#: mono 1.1.13.7
> perl: perl 5.8.8
> python: python 2.4.2
> ruby: ruby 1.8.4
>

yer dreemin sorry not intrestied due yer onn homework 




------------------------------

Date: 21 Oct 2006 12:35:58 -0700
From: "sturlamolden" <sturlamolden@yahoo.no>
Subject: Re: A Comparison Of Dynamic and Static Languiges
Message-Id: <1161459358.506368.217150@m73g2000cwd.googlegroups.com>


atbusbook@aol.com wrote:

> c#: mono 1.1.13.7
> perl: perl 5.8.8
> python: python 2.4.2
> ruby: ruby 1.8.4

And why would any of this tell you anything about static versus dynamic
languages? The languages you list are all dependent on different
runtimes, and your results will simply reflect that. It would not tell
you anything about how the dynamic or static nature of the language
affects the execution speed.

Common Lisp is dynamic just like Python, and there are interpreted and
compiled implementations of it. It is common knowledge that interpreted
Lisp is "slow". Fewer know that compiled Lisp runs nearly at the speed
of C, albeit being a dynamic language. So how would you conclude if you
added a compiled implementation of Common Lisp to your list?



------------------------------

Date: Sun, 22 Oct 2006 01:41:51 +0100
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: avoid multiple script startup overhead
Message-Id: <g69wt6ttc4w.fsf@lifelogs.com>

Consider the daemontools package.

They will start a process AND keep it running, whatever happens.  So
if your scripts need to run every N minutes as opposed to at a
specific hour, just put them under daemontools with a main loop that
runs some code and then sleeps N minutes.  If your program dies, it
will probably do so during the code section.  Depending on your
requirements, you can make the startup sleep() and THEN run the code,
so you don't have lots of quick failures in sequence, or you can make
the startup run the code and THEN sleep(), if you want to ensure that
a single failure doesn't slow things down.  You can make the startup
more complicated, of course, depending on how much effor you want to
invest.

The biggest win from this approach is that you no longer rely on cron
to keep your scripts running, and there's no startup penalty.  You
lose the precise knowledge of when your scripts are starting, though.

Daemontools does some other nice things; I especially like the logging
approach with the multilog program.

Ted


------------------------------

Date: Sun, 22 Oct 2006 01:16:56 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Matching umlauts
Message-Id: <ehegrv.bo.1@news.isolution.nl>

Peter J. Holzer schreef:


> [translating accented letters to unaccented]
> Unicode has the concept of "combining characters". So "\x{00FC}"
> (LATIN SMALL LETTER U WITH DIAERESIS) is really the same as
> "\x{0075}\x{0308}" (LATIN SMALL LETTER U followed by COMBINING
> DIAERESIS). There are rules for "canonicalization" or "normalization"
> which determine which of the equivalent forms should be used. By
> canonicalizing to the longes[t] form (i.e replacing each "\x{00FC}"
with
> "\x{0075}\x{0308}" and then stripping the combining characters you
> would replace all accented characters with their base characters and
> so turn "München" into "Munchen".
>
> There is a perl module Unicode::Normalize, which I think should do
> what you want but I've never used it.

That is indeed a workable way to do it.

-- 
Affijn, Ruud

"Gewoon is een tijger."



------------------------------

Date: 21 Oct 2006 11:18:18 -0700
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Reverse algorithm with tangent
Message-Id: <1161454698.765195.25800@k70g2000cwa.googlegroups.com>

Bart Van der Donck wrote:
>
> Here is some code:
>
>     use Math::Trig;
>     my $v = 0.6235584253;
>     for (0..9)  {
>       $v = $v + 1;
>       $v = tan ($v); # tangent
>       $v =~ s/\d{1,}\./0./; # no ^ for possible minus
>     }
>     print $v;
>
> It prints -0.86659174554348. Is it logically/technically possible to
> reverse this calculation ? In this example: start with
> -0.86659174554348 and end up with 0.6235584253.


Dear Bart,

   I would think that it's not possible to logically reverse this
calculation, and here's why I think so:

   Every time you loop you set $v to its tangent ( with $v = tan($v); )
and then mod it by 1.  Let's just say, for the sake of argument, that
the first time through the loop tan($v) evaluates to 1.5 .  The very
next line would set $v to 0.5 .

   But now let's assume that $v was a greater value, one that would
make tan($v) evaluate to 2.5 .  The very next line would still set $v
to 0.5 .

   In fact, there are an infinite number of unique values that would
make tan($v) evaluate to 1.5, 2.5, 3.5, 4.5, 5.5, etc. -- which would
all make $v become 0.5 in the very next line.

   Therefore, if you're reversing this algorithm, it would be
impossible to know which of those values is the right one to obtain
when reversing the line that performs the mod 1 operation.  And that's
why I don't think it's possible to reverse this calculation.

   (But then again, I could be wrong...   ;)

   I hope this helps, Bart.

   -- Jean-Luc



------------------------------

Date: 21 Oct 2006 20:39:48 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Reverse algorithm with tangent
Message-Id: <eaqkj2178nofnkftphgapa2onueaed15ue@4ax.com>

On 21 Oct 2006 08:59:58 -0700, "Bart Van der Donck" <bart@nijlen.com>
wrote:

>It prints -0.86659174554348. Is it logically/technically possible to
>reverse this calculation ? In this example: start with
>-0.86659174554348 and end up with 0.6235584253.

How 'bout atan()?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Sat, 21 Oct 2006 20:48:18 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reverse algorithm with tangent
Message-Id: <slrnejkqri.hoj.hjp-usenet2@yoyo.hjp.at>

On 2006-10-21 15:59, Bart Van der Donck <bart@nijlen.com> wrote:
> Here is some code:
>
>     use Math::Trig;
>     my $v = 0.6235584253;
>     for (0..9)  {
>       $v = $v + 1;
>       $v = tan ($v); # tangent
>       $v =~ s/\d{1,}\./0./; # no ^ for possible minus
>     }
>     print $v;
>
> It prints -0.86659174554348. Is it logically/technically possible to
> reverse this calculation ? In this example: start with
> -0.86659174554348 and end up with 0.6235584253.

I don't think so: This function isn't smooth and it doesn't even have
smooth intervals of any useful length.

> This topic was earlier started in sci.math, but no result.
> (http://groups.google.com/group/sci.math/browse_frm/thread/2b7a2fd0737ffb28/)

There you relaxed the requirements a bit: You don't need to get back to
0.6235584253, it is enough to find any value which when fed into your
function gives the result -0.86659174554348.

This makes it a lot easier. We know that at the start and end of each
loop $v has a value between -1 and 1, and that the tan function has a
periodicity of pi. So we can reverse your function like this:


#!/usr/bin/perl
use warnings;
use strict;
use Math::Trig;

sub f {
    my ($v) = @_;

    for (0..9)  {
      $v = $v + 1;
      $v = tan ($v); # tangent
      $v =~ s/\d{1,}\./0./; # no ^ for possible minus
    }
    return $v;
}

sub rf {
    my ($v) = @_;
    for (0 .. 9) {
	my $s = $v >= 0 ? 1 : -1;

	FIND_INT:
	for my $i (0 .. 100) { # should really be 0 .. infinity
	    my $vx = $v + $i * $s;
	    $vx = atan2($vx, 1);
	    if (abs ($vx - 1) < 1) {
		$v = $vx - 1;
		last FIND_INT;
	    } elsif (abs ($vx + pi - 1) < 1) {
		$v = $vx + pi - 1;
		last FIND_INT;
	    } 
	}
    }
    return $v;
}

my $v = 0.6235584253;
print $v, "\n";

$v = f($v);
print $v, "\n";

$v = rf($v);
print $v, "\n";

$v = f($v);
print $v, "\n";

Which prints:

0.6235584253
-0.86659174554348
-0.217377922712057
-0.86659174566011

is -0.86659174566011 close enough to -0.86659174554348 for your
purposes?

Note that the rf function returns a value between -1 and 1, although you
specified that the original value is between 0 and 1. Modifying it to
produce a result between 0 and 1 is left as an exercise for the reader
:-).

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


------------------------------

Date: 21 Oct 2006 13:25:00 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: Reverse algorithm with tangent
Message-Id: <1161462300.616756.159690@f16g2000cwb.googlegroups.com>

Peter J. Holzer wrote:

> On 2006-10-21 15:59, Bart Van der Donck <bart@nijlen.com> wrote:
> > Here is some code:
> >
> >     use Math::Trig;
> >     my $v = 0.6235584253;
> >     for (0..9)  {
> >       $v = $v + 1;
> >       $v = tan ($v); # tangent
> >       $v =~ s/\d{1,}\./0./; # no ^ for possible minus
> >     }
> >     print $v;
> >
> > It prints -0.86659174554348. Is it logically/technically possible to
> > reverse this calculation ? In this example: start with
> > -0.86659174554348 and end up with 0.6235584253.
> > [...]
> > (http://groups.google.com/group/sci.math/browse_frm/thread/2b7a2fd0737ffb28/)
>
> There you relaxed the requirements a bit: You don't need to get back to
> 0.6235584253, it is enough to find any value which when fed into your
> function gives the result -0.86659174554348.
>
> This makes it a lot easier. We know that at the start and end of each
> loop $v has a value between -1 and 1, and that the tan function has a
> periodicity of pi. So we can reverse your function like this:
> [snip code]

Thanks for the code, it's further than I got. I think you're absolutely
right that a lot changes when the requirement is only to return 'any'
start value, not 'the' start value. The real-world background is
password encryption algorithms here, so the 'any' start value suits
indeed.

I believe the core of this problem is the line where it says:

  $v =~ s/\d{1,}\./0./;

(in maths: v = v % 1), because at this point something is 'dropped',
namely the found digits before the dot (or, in Perl, the $1-variable of
the regex). It can't be retrieved anymore, but, for an exact reverse to
the same start value, that is an absolute requirement. Probably there
must exist some logical/mathematical term for such phenomenons. My
conclusion at this point  would be that the same start value cannot be
obtained anymore.

(One workaround could be to push the $1's to an array and use that
array in the reverse-routine, but this would of course be a fallacy
since the start value must be known in order to fill the array).

But that doesn't say anything about whether or not the 'any' start
value can be fetched indeed.

> Which prints:
> 0.6235584253
> -0.86659174554348
> -0.217377922712057
> -0.86659174566011
> is -0.86659174566011 close enough to -0.86659174554348 for your
> purposes?

Unfortunately, no. It must be further parsed to a character string
which needs the exact digits after the dot (minus or not doesn't
matter).

The first thing that comes to mind is the accuracy of Math::Trig's
tan() and atan() functions, because it must be extremely precise for
the repeated tan()/atan() calls.

Maybe you've written the right code. I need some time to study that. I
see exactly the same results as you, so I'ld say it's probably not
related to the OS. Maybe Perl or Math::Trig blocks off after a certain
range of digits, or it has something to do with
http://faq.perl.org/perlfaq4.html#Why_am_I_getting_lon

> Note that the rf function returns a value between -1 and 1, although you
> specified that the original value is between 0 and 1. Modifying it to
> produce a result between 0 and 1 is left as an exercise for the reader
> :-).

Can do! :-)

-- 
 Bart



------------------------------

Date: Sat, 21 Oct 2006 22:44:09 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reverse algorithm with tangent
Message-Id: <slrnejl1kp.mc3.hjp-usenet2@yoyo.hjp.at>

On 2006-10-21 18:39, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On 21 Oct 2006 08:59:58 -0700, "Bart Van der Donck" <bart@nijlen.com>
> wrote:
>>It prints -0.86659174554348. Is it logically/technically possible to
>>reverse this calculation ? In this example: start with
>>-0.86659174554348 and end up with 0.6235584253.
>
> How 'bout atan()?

Doesn't help by itself: His function contains two non-injective
periodic functions (tan() and %) and each is applied 10 times. This
means that there are Infinity**20 possible values in the domain which
map to the same value in the range.

I've outlined a way to get one of these values in a different post (I do
use atan2, but that's the simple part).

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


------------------------------

Date: Sat, 21 Oct 2006 21:19:04 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Reverse algorithm with tangent
Message-Id: <ehe2s8$11eh$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Bart Van der Donck
<bart@nijlen.com>], who wrote in article <1161462300.616756.159690@f16g2000cwb.googlegroups.com>:
> > is -0.86659174566011 close enough to -0.86659174554348 for your
> > purposes?
> 
> Unfortunately, no. It must be further parsed to a character string
> which needs the exact digits after the dot (minus or not doesn't
> matter).

tan' is always 1 or more; thus your "encryption" function also has
derivative of 1 or more.  Hence the "decryption" function has
derivative 1 or less.

Essentially, what it means in this example is that there is no "loss
of precision"; given 39 digits after the point in the encrypted value,
you should expect to completely restore 39 digits after the poinit in
the decrypted value.  All you need is doing calculation with high
enough precision, so the errors do not accumulate.

So do the calcs in some higher-precision-math Perl module.

[Of course, what I said depends a lot on the fact that only 10 rounds
of calculation are made, thus there are significantly long intervals
of smoothness; I would not be surprised if about 40 rounds these
intervals would decrease to be short enough to contain at most 1
exactly representable in `double' number...]

Hope this helps,
Ilya


------------------------------

Date: 21 Oct 2006 23:31:19 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Reverse algorithm with tangent
Message-Id: <0a4lj216b1dd74dbjqhhslie608f35mjv4@4ax.com>

On Sat, 21 Oct 2006 22:44:09 +0200, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:

>Doesn't help by itself: His function contains two non-injective
>periodic functions (tan() and %) and each is applied 10 times. This

Indeed, hadn't actually read the full post, and in particular the
actual code, just noticed an application of tan() and a sign trick.
Apologies for raising the noise/signal ratio.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Sat, 21 Oct 2006 23:27:59 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reverse algorithm with tangent
Message-Id: <slrnejl46v.n01.hjp-usenet2@yoyo.hjp.at>

On 2006-10-21 20:25, Bart Van der Donck <bart@nijlen.com> wrote:
> Peter J. Holzer wrote:
>
>> On 2006-10-21 15:59, Bart Van der Donck <bart@nijlen.com> wrote:
>> > Here is some code:
>> >
>> >     use Math::Trig;
>> >     my $v = 0.6235584253;
>> >     for (0..9)  {
>> >       $v = $v + 1;
>> >       $v = tan ($v); # tangent
>> >       $v =~ s/\d{1,}\./0./; # no ^ for possible minus
>> >     }
>> >     print $v;
>> >
>> > It prints -0.86659174554348. Is it logically/technically possible to
>> > reverse this calculation ? In this example: start with
>> > -0.86659174554348 and end up with 0.6235584253.
>> > [...]
>> > (http://groups.google.com/group/sci.math/browse_frm/thread/2b7a2fd0737ffb28/)
>>
>> There you relaxed the requirements a bit: You don't need to get back to
>> 0.6235584253, it is enough to find any value which when fed into your
>> function gives the result -0.86659174554348.
>>
>> This makes it a lot easier. We know that at the start and end of each
>> loop $v has a value between -1 and 1, and that the tan function has a
>> periodicity of pi. So we can reverse your function like this:
>> [snip code]
>
> Thanks for the code, it's further than I got. I think you're absolutely
> right that a lot changes when the requirement is only to return 'any'
> start value, not 'the' start value. The real-world background is
> password encryption algorithms here, so the 'any' start value suits
> indeed.
>
> I believe the core of this problem is the line where it says:
>
>   $v =~ s/\d{1,}\./0./;
>
> (in maths: v = v % 1), because at this point something is 'dropped',
> namely the found digits before the dot (or, in Perl, the $1-variable of
> the regex). It can't be retrieved anymore, but, for an exact reverse to
> the same start value, that is an absolute requirement. Probably there
> must exist some logical/mathematical term for such phenomenons.

The function is not "injective".

(Note that tan isn't injective in the general case, either. However,
since it gets only input values between 0 and 2 in your code, it is,
except possibly for values very close to pi/2)

[...]

>> Which prints:
>> 0.6235584253
>> -0.86659174554348
>> -0.217377922712057
>> -0.86659174566011
>> is -0.86659174566011 close enough to -0.86659174554348 for your
>> purposes?
>
> Unfortunately, no. It must be further parsed to a character string
> which needs the exact digits after the dot (minus or not doesn't
> matter).
>
> The first thing that comes to mind is the accuracy of Math::Trig's
> tan() and atan() functions, because it must be extremely precise for
> the repeated tan()/atan() calls.
>
> Maybe you've written the right code. I need some time to study that. I
> see exactly the same results as you, so I'ld say it's probably not
> related to the OS. Maybe Perl or Math::Trig blocks off after a certain
> range of digits,

It certainly does: IEEE-754 double precision floating point numbers have
53 bits of precision. Even if the tan and atan functions are as precise
as possible (the relative error is less than 2**-54), the rounding
errors add up quite a bit. 

Actually, I don't think tan and atan are that precise: These functions
are computed by a series, and I believe that normally only a small
fixed number of elements in the series is computed. The manual for your
CPU might tell you the maximum error for certain number ranges. I would
not be surprised if different CPUs[0] produce different results.

I see two possible ways to improve the code:

1) For each step, make sure that the computed value matches exactly.
   If it doesn't it may be possible to compute a better value with
   Newton's method. If there isn't, skip it.

2) Check the final computed value. If it doesn't match, backtrack.

	hp

[0] For completeness, here's /proc/cpuinfo of my laptop:
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 8
    model name      : Pentium III (Coppermine)
    stepping        : 10


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


------------------------------

Date: Sat, 21 Oct 2006 23:40:18 +0100
From: "Alison" <alison@logicsaysNOSPAM.com>
Subject: Re: Sorting Data in Two Columns
Message-Id: <_NadnXZVm7QsPKfYRVnyvA@bt.com>

John Bokma <john@castleamber.com> wrote in message
news:Xns98637A49441F0castleamber@130.133.1.4...

Ahhh, now that's where it gets interesting.  I'll try to describe.

A .csv logfile is appended each time log.pl is called, either from an SSI or
a Java documentwrite hack.

Generally there are about 2000 hits daily.  Each single record has 6 pieces
of information; Hit, Time, Data, URL, IP, Referrer.

1. .csv is opened and records/line read one by one.
2. Match performed on an array, else insert, increment counter for element.
3. Total records recorded.
4. HTML table rows outputted with information from array.

Following the information I have here, I'm now doing;

4. One dimensional array copied into Two Dimensional array.
5. Two Dimensional array sorted.
6. Two Dimensional array copied back into One Dimensional array
7. HTML table rows outputted with information from array.

Definitely messy.  It's using about 2.0% processor usage as reported by Unix
TOPS.

The next .pl that I write I'll start off with a Two Dimensional array from
the beginning and will then write it back into the original .pl scripts.

This is purely so my partner can monitor traffic on the site.  I had
previously been on a shared hosted server and attracted the attention of the
company admins for using too much processor time.

I've just moved over to a virtual dedicated server running Fedora 4/Red Hat,
and that dreadful Plesk windows style panel thing.  I don't have root access
as to do so would mean that the server isn't supported on site.  Plesk
apparently does strange things when the UNIX config is altered directly
underneath it.

Normally I would just download the .csv files but am unable to do so since
Plesk 8.0 which denies write/modify access to scripts outside of the cgi-bin
directory.  And all files within the cgi-bin directory are treated and ran
as scripts regardless of name.

Hence I've had to write these Perl apps.  Without root access I don't have
access to the Apache logs either :-(.  And it can't be changed since the
server would be unsupported as non-standard from the Plesk vision of Windoze
style configurable Linux.

A balance overall really of what I've got..

Alison




------------------------------

Date: Sat, 21 Oct 2006 23:42:22 +0100
From: "Alison" <alison@logicsaysNOSPAM.com>
Subject: Re: Sorting Data in Two Columns
Message-Id: <xZidnY-VzuO0P6fYnZ2dnUVZ8tOdnZ2d@bt.com>


Mumia W. (reading news) <paduille.4060.mumia.w@earthlink.net> wrote in
message news:5xl_g.12528$Y24.10935@newsread4.news.pas.earthlink.net...
> On 10/20/2006 07:41 PM, Alison wrote:

Hi Mumia,

That's the ticket! :-)  Thanks :-)

Done.

Alison




------------------------------

Date: Sat, 21 Oct 2006 20:33:26 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: unable to calculate large file size
Message-Id: <slrnejkpvm.hoj.hjp-usenet2@yoyo.hjp.at>

On 2006-10-21 17:59, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Sat, 21 Oct 2006 18:59:56 +0200, "Peter J. Holzer"
><hjp-usenet2@hjp.at> wrote:
>
>>    /usr/bin/perl -e 'print -s "foo", "\n"'
>>
>>It should print something like
>>
>>    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
>>                                  ^^^^^^^^^^^^^^^^^^^^
>
> Really?!? ;-)

Oops. Wrong line in the clipboard. Should have been

    perl -V | grep large

instead.

>   perl -V:uselargefiles

This is of course even better but requires you to know the exact
spelling of the option, while for the grep you only need to remember
that it has something to do with "large".

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9876
***************************************


home help back first fref pref prev next nref lref last post