Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: √ ∞ ≠ ≤ ≥ ≈ ⇒ ∈ Δ θ ∴ ∑ ∫ π -

Login

Username

Password

Not registered yet?

Post a reply

Go back

Write your message and submit
:) :| :( :D :o ;) :/ :P :lol: :mad: :rolleyes: :cool: | :dizzy :eek :kiss :roflol :rolleyes :shame :down :up :touched :sleep :wave :swear :tongue :what :faint :dunno
Options

Go back

Topic review (newest first)

Ricky
2006-05-08 00:15:22

Dang.  You're right George.  I was hoping since they had to have similar terms they could be be factored out into the same part, but nope.  A temporary fix to this is to have 3 different terms, each with the same structure, but different integer coefficents.  But that is really unacceptable in terms of performance.

I think a different approach is needed.  Testing all possibilities just won't work.  We need a way of eliminating some right off the bat.

George,Y
2006-05-07 19:32:04

What if a third similar element added to your formula? It can't be covered by the old one.

Ricky
2006-05-07 11:20:22

The code is easy to understand (try every combination). In your test you could use "abs(n-m)  < EPSILON", but that may not be faster.

That actually should be faster, however, it certainly isn't the bottle neck of the code.  So it won't really be a big increase, but hey, an increase none the less.

I've thought about doing as you suggested, to return the difference.  However, I'm not entirely sure whether this willl allow me to skip some loops.

MathsIsFun
2006-05-07 10:33:39

Ummm... I think I need more explanation.

Firstly, it will find π because π is in the formula!

Anyway, please tell me more so my poor brain can assimilite it.

The code is easy to understand (try every combination). In your test you could use "abs(n-m)  < EPSILON", but that may not be faster.

Another idea would be for the test to return the difference, and to then cut some of the loops short if they will take you further away: (each loop could have a "last difference" variable to see if it is moving further from zero). Only if you can be sure it will continue in that direction of course.

Ricky
2006-05-07 05:54:44

Let's face it, we all hate decimals.  Especially when it comes to irrational numbers.  Who really wants to write something out for infinity when just writing "e" will do the job.

So I was thinking, can we take a decimal approximation and use it to find an irrational number that is near it?  Now when I say near, what I mean is that hopefully, we will stumble upon the exact solution, if it is in fact irrational.

Let a, b, c, d, f, g, h, i, j, k, l, m, n, o be integers.  A general equation for irrationals I have come up with is:



Which of course doesn't cover all irrationals, but it should cover a heck of a lot of them.  If anyone can either:

1. Simplify this so that it includes less variables
2. Find an irrational this does not cover

I've already made code to handle this, although it takes a heck of a long time to run.  And that's only for very small values.  It was able to find pi and sqrt(pi) already, although those were easy tests.  Right now, I'm having it run on
just for kicks, to see if it comes up with anything.  For those of you who don't know, we only have an approximation for that summation.

Here is my code:

Code:

#include <iostream>
#include <math.h>

#define EULER 2.718281828459
#define PI 3.14159265
#define EPSILON 0.0000001

using namespace std;

bool test(double n, double m)
{
    if (n - EPSILON < m && n + EPSILON > m) return true;
    return false;
}
int main()
{
    double a,b,c,d,f,g,h,i,j,k,l,m,n,o;
    double input;
    cout << "Enter number: " << endl;
    cin >> input;

    int start = 0; int end = 10;

    for (a = start; a < end; a++)
    {
    for (b = start; b < end; b++)
    {
    for (c = start; c < end; c++)
    {
    for (d = start; d < end; d++)
    {
    for (f = start; f < end; f++)
    {
    for (g = start; g < end; g++)
    {
    for (h = start; h < end; h++)
    {
    for (i = start; i < end; i++)
    {
    for (j = start; j < end; j++)
    {
    for (k = start; k < end; k++)
    {
    for (l = start; l < end; l++)
    {
    for (m = start; m < end; m++)
    {
    for (n = start; n < end; n++)
    {
    for (o = start; o < end; o++)
    {
        double part1 = pow(a/b*pow(EULER, c/d)*pow(PI, f/g), h/i);
        double part2 = j/k*pow(EULER, l/m)*pow(PI, n/o);

        if (test(input, part1 + part2))
        {
            cout << "(" << a << "/" << b << "e^(" << c << "/" << d << ")pi^(" << f << "/"
                << g << ")^(" << h << "/" << i << ") + " << j << "/" << k << "e^(" << l <<
                "/" << m << ")pi^(" << n << "/" << o << ") " << endl;
            return 0;
        }
    }}}}}}}}}}}}}}
    return 0;
}

Board footer

Powered by FluxBB