Re: How can I make FullSimplify work for user-defined functions?

• To: mathgroup at smc.vnet.net
• Subject: [mg52595] Re: [mg52569] How can I make FullSimplify work for user-defined functions?
• From: DrBob <drbob at bigfoot.com>
• Date: Fri, 3 Dec 2004 03:54:14 -0500 (EST)
• References: <200412020721.CAA05840@smc.vnet.net> <opsidxdbzviz9bcq@monster.cox-internet.com>
• Reply-to: drbob at bigfoot.com
• Sender: owner-wri-mathgroup at wolfram.com

```Here's a faster MGPP:

Clear@myMGPP
myMGPP[n_Integer?EvenQ] /; n > 3 :=
Block[{m = PrimePi[n/2], p},
While[! PrimeQ[n - (p = Prime@m)], m--];
{p, n - p}]

Bobby

On Thu, 02 Dec 2004 08:33:01 -0600, DrBob <drbob at bigfoot.com> wrote:

> Something like this may work for you:
>
> newlb /:
>    newlb[(n_Integer)?EvenQ] <=
>       pval[n_] /; Inequality[4,
>       LessEqual, n, Less,
>       10^6] := True
>
> newlb[100] <= pval[100]
> True
>
> By the way, here's a significantly faster (and FAR simpler) pvalue function:
>
> Needs["NumberTheory`NumberTheoryFunctions`"]
> myP[n_] :=
>    Block[{m = PrimePi[n/2], p},
>      While[! PrimeQ[n - (p = Prime@m)], m--];
>      p]
>
> pvalue[n_] := Module[{p, m, k, hit}, {m =
>      n/2; If[Element[m, Primes], {p = m}, {k = PrimePi[m];
>            Do[If[Element[n - Prime[i], Primes], hit = i;
>                Break[]], {i, k, 1, -1}], p = Prime[hit]}]}; p]
>
> n = 100000;
> Timing[mine = myP /@ Range[4, n, 2];]
> Timing[yours = pvalue /@ Range[4, n, 2];]
> mine == yours
>
> {2.75 Second,Null}
>
> {3.766 Second,Null}
>
> True
>
> Here's a corresponding version of MGPP, also with timings:
>
> myMGPP = {0, #} + {1, -1}myP@# &;
>
> MGPPP[n_] := Module[{p, q}, {m = n/2;
>   If[Element[m, Primes], {p = m, q = m}, {k = PrimePi[m];
>            Do[If[Element[n - Prime[i], Primes], hit = i;
>                Break[]], {i, k, 1, -1}], p = Prime[hit], q = n - p}]}; {p, q}]
>
> n = 100000;
> Timing[mine = myMGPP /@ Range[4, n, 2];]
> Timing[yours = MGPPP /@ Range[4, n, 2];]
>
> {3.031 Second,Null}
>
> {3.485 Second,Null}
>
> Bobby
>
> On Thu, 2 Dec 2004 02:21:28 -0500 (EST), Gilmar Rodr?guez Pierluissi <gilmar.rodriguez at nwfwmd.state.fl.us> wrote:
>
>> (First; a necessary short introduction, and then
>>  two questions.  Please, bear with me...)
>>
>> Let N be an even integer greater or equal to 4.
>>
>> Assume that there exist points (Pi, Qi) on the line
>> Y = -X + N such that:
>>
>> (1.) both Pi, and Qi are primes,
>>
>> (2.) the points (Pi,0) are on the subinterval [2,N/2]
>>       of the X-Axis,
>>
>> (3.) the points (0,Qi) are on the subinterval [N/2,N-2]
>>       of the Y-Axis.
>> A Minimal Goldbach Prime Partition Point corresponding
>> to N,(abbreviated: "MGPPP[N]")is a point (P,Q) among
>> the points (Pi,Qi)  such that:
>>
>> the distance between the point (P,Q) and the point (N/2,N/2)
>>
>> = smallest distance among all distances between
>>   the points (Pi, Qi) and the point (N/2, N/2).
>>
>> If N is of the form N = 2P then MGPPP[N] = (N/2,N/2).
>>
>> If N is of the form N = P + Q, with P not equal to Q, then
>> MGPPP[N] = (P,Q).
>>
>> For geometrical pictures please visit:
>> http://gilmarlily.netfirms.com/goldbach/goldbach.htm
>>
>> (version 5.0)by double-cliking this link:
>>
>>
>> You can use this notebook to duplicate the evaluations
>> appearing in the discussion below:
>>
>> Having said the above; the following program
>> calculates the MGPPP[N]:
>>
>> MGPPP[n_] := Module[{p, q},
>>     {m = n/2; If[Element[m,
>>     Primes], {p = m, q = m}, {k =PrimePi[m];
>>     Do[If[Element[n - Prime[i], Primes], hit = i;
>>     Break[]], {i, k, 1, -1}],p = Prime[hit],
>>     q = n - p}]}; {p, q}]
>>
>> Examples:
>>
>> MGPPP[4]={2,2}
>>
>> MGPPP[100]={47,53}.
>>
>> The above program can be easily changed as follows to give
>> only the "p-value" (instead of the point {p,q}):
>>
>> pvalue[n_] := Module[{p},
>>     {m = n/2; If[Element[m,
>>     Primes], {p = m}, {k =PrimePi[m];
>>     Do[If[Element[n - Prime[i], Primes], hit = i;
>>     Break[]],{i, k, 1, -1}], p = Prime[hit]}]}; p]
>>
>> A plot to depict the p-values is given by:
>>
>> plt1=ListPlot[Table[pvalue[n],{n,4,100,2}],PlotJoined®True,
>> PlotStyle®Hue[0.1]]
>>
>> It has been conjectured that the Minimal Goldbach Prime Partition
>> p-values have a lower bound given by:
>>
>> Prime[PrimePi[Sqrt[N]].
>>
>> To visualize this do:
>>
>> (** oldlb= abbreviation for old lower bound. **)
>>
>> oldlb[n_]:=Prime[PrimePi[Sqrt[n]]];
>>
>> plt2=ListPlot[Table[oldlb[n],{n,4,100,2}],
>> PlotJoined®True,PlotStyle®Hue[0.2]]
>>
>> Show[plt1,plt2]
>>
>> Try also:
>>
>> TableForm[Table[{n,oldlb[n],pvalue[n]},{n,4,100,2}],
>> TableAlignments->Center]
>>
>> However; that lower bound can be improved by the following
>> new lower bound:
>>
>> Prime[PrimePi[(N+2*Sqrt[N])/4].
>>
>> The following program makes use of this latest interval:
>>
>> pval[n_] := Module[{p},
>>     {m = n/2; If[Element[m,
>>     Primes], {p = m}, {k =PrimePi[m];
>>     l=PrimePi[(n+2*Sqrt[n])/4];
>>     Do[If[Element[n - Prime[i], Primes], hit = i;
>>           Break[]], {i, k, l, -1}], p = Prime[hit]}]}; p]
>>
>> To compare the p-values with the old and new lower bounds do:
>>
>> plt3=ListPlot[Table[pval[n],{n,4,100,2}],PlotJoined®True,
>> PlotStyle®Hue[0.1]]
>>
>> newlb[n_]:=Prime[PrimePi[(n+2*Sqrt[n])/4]]
>>
>> plt4=ListPlot[Table[newlb[n],{n,4,100,2}],
>> PlotJoined®True,PlotStyle®Hue[0.6]]
>>
>> Show[plt3,plt4]
>>
>> Show[plt2,plt3,plt4]
>>
>> Try also:
>>
>> TableForm[Table[{n,newlb[n],pval[n]},{n,4,100,2}],
>> TableAlignments->Center]
>>
>>
>> Finally; I try the FullSimplify command, to test the validity
>> of the new bound,via:
>>
>> FullSimplify[newlb[n]<= pval[n],Element[n,EvenQ]&&n³4]
>>
>> hoping that this evaluation gives me "True" as a result.
>>
>> I get instead a cryptic:
>>
>> "Prime[PrimePi[1/4(2Sqrt[n]+n)]]<= p\$214"
>>
>>
>> Then I realize: one would really need to prove Goldbach's Conjecture first,
>> so that the "True" after the above FullSimplify evaluation is truly valid.
>>
>> So I try instead:
>>
>> FullSimplify[newlb[n]<=pval[n],Element[n,EvenQ]&&n³4&&n<10^6]
>>
>> and this time I get:
>>
>> "Prime[PrimePi[1/4(2Sqrt[n]+n)]]<= p\$358".
>>
>> My questions are:
>>
>> (1.) How can I make FullSimplify work for user-defined functions?
>>
>> (2.) How can I make
>>      FullSimplify[newlb[n]<=pval[n],Element[n,EvenQ]&&n³4&&n<10^6]
>>      "True"?
>>
>> Thank you for your attention, and your help!
>>
>>
>>
>>
>
>
>

--
DrBob at bigfoot.com
www.eclecticdreams.net

```

• Prev by Date: Re: How can I make FullSimplify work for user-defined functions?
• Next by Date: Using LevenbergMarquardt Method with a complicated function
• Previous by thread: Re: How can I make FullSimplify work for user-defined functions?
• Next by thread: Re: How can I make FullSimplify work for user-defined functions?