Mathematics is one of the only areas of knowledge that can objectively be described as "true," because its theorems are derived from pure logic. And yet, at the same time, those theorems are often extremely strange and counter-intuitiveSo @
nsaspook
where do yo expect this conversation to go ?
As this is not in general chat , I assume it has an end point / objective ?
Exactly.Yes that is one that we always have to keep in mind when comparing results from floating point arithmetic.
So it can be even simpler than that:
2!=2
sometimes.
This is also interesting because sometimes it will print out in a console as "2" when really it is "1.9999999999999999" or something like that. Depends on the print format specifiers being used.
That is why it is good to use an algorithm to compare results.
#include "float.h"
#include "stdlib.h"
typedef double real;
int real_compare(double lhs, double rhs, double eps) {
if(eps == 0)
eps = DBL_EPSILON;
double dif = lhs - rhs;
if (abs(dif) <= eps)
return 0;
if (dif < 0)
return dif < eps ? -1 : 1;
return dif > eps ? 1 : -1;
}
#define real_same(lhs, rhs, eps) (real_compare(lhs, rhs, eps) == 0)
#define real_less(lhs, rhs, eps) (real_compare(lhs, rhs, eps) < 0)
#define real_same_or_less(lhs, rhs, eps) (real_compare(lhs, rhs, eps) <= 0)
#define real_more(lhs, rhs, eps) (real_compare(lhs, rhs, eps) > 0)
#define real_same_or_more(lhs, rhs, eps) (real_compare(lhs, rhs, eps) >= 0)
#include "math.h"
#include "stdio.h"
int main(int argc, char** argv) {
real two = pow(sqrt(2), 2);
real computed = two + two;
real actual = 4;
printf("computed: %g\n", computed);
printf("actual: %g\n", actual);
printf("computed == actual: %s\n", computed == actual ? "TRUE" : "FALSE");
printf("real_same(computed, actual, DBL_EPSILON): %s\n",
real_same(computed, actual, DBL_EPSILON) ? "TRUE" : "FALSE");
printf("real_less(computed, actual, DBL_EPSILON): %s\n",
real_less(computed, actual, DBL_EPSILON) ? "TRUE" : "FALSE");
printf("real_same_or_less(computed, actual, DBL_EPSILON): %s\n",
real_same_or_less(computed, actual, DBL_EPSILON) ? "TRUE" : "FALSE");
printf("real_more(computed, actual, DBL_EPSILON): %s\n",
real_more(computed, actual, DBL_EPSILON) ? "TRUE" : "FALSE");
printf("real_same_or_more(computed, actual, DBL_EPSILON): %s\n",
real_same_or_more(computed, actual, DBL_EPSILON) ? "TRUE" : "FALSE");
}
computed: 4
actual: 4
computed == actual: FALSE
real_same(computed, actual, DBL_EPSILON): TRUE
real_less(computed, actual, DBL_EPSILON): FALSE
real_same_or_less(computed, actual, DBL_EPSILON): TRUE
real_more(computed, actual, DBL_EPSILON): FALSE
real_same_or_more(computed, actual, DBL_EPSILON): TRUE
It has no end point! Take the number "1" simple right! Wrong! 1= 0.999, followed by an infinite string of nines, is equivalent to one, people don't believe it could be true. The left side represents the beginning of mathematics; the right side represents the mysteries of infinity.As this is not in general chat , I assume it has an end point / objective ?
I was meaning as to where this general conversation on anything was going ,It has no end point! Take the number "1" simple right! Wrong! 1= 0.999, followed by an infinite string of nines, is equivalent to one, people don't believe it could be true. The left side represents the beginning of mathematics; the right side represents the mysteries of infinity.
What are you the thread police all of a sudden?So @
nsaspook
where do yo expect this conversation to go ?
As this is not in general chat , I assume it has an end point / objective ?
I am familiar with that one. It is another interesting view on what infinity is.It has no end point! Take the number "1" simple right! Wrong! 1= 0.999, followed by an infinite string of nines, is equivalent to one, people don't believe it could be true. The left side represents the beginning of mathematics; the right side represents the mysteries of infinity.
NO MrAI,What are you the thread police all of a sudden?
Some conversations get more interesting as time goes on even if they diverge a little.
We sometimes talk about related things, that's all there is to it.
Oh ok, it sounded like you have a problem with conversations that may diverge a little.NO MrAI,
I am just asking.
Anything wrong with that ?
Is my view any less relevant than yours ?
If that is how you view life, how do you manage to get out of bed, put your pants on and serve yourself any food? Logical masterbation is fun for everyone but at some point, the fun and games stop and a person has to figure out how to feed themselves.It has no end point! Take the number "1" simple right! Wrong! 1= 0.999, followed by an infinite string of nines, is equivalent to one, people don't believe it could be true. The left side represents the beginning of mathematics; the right side represents the mysteries of infinity.
As an undergraduate applied mathematics major, I was taught that 2+2=5, for large values of 2 and small values of 5…It has no end point! Take the number "1" simple right! Wrong! 1= 0.999, followed by an infinite string of nines, is equivalent to one, people don't believe it could be true. The left side represents the beginning of mathematics; the right side represents the mysteries of infinity.
There is an entire community here that will help you "deal with it".But, I hope I will deal with it
You are not alone.That's for sure! That is why learning math is very difficult for me
I have a windows version written in C# if you are interested.I love "The game of life" - It was one of the original programs that I wrote in C.
I showed my girlfriend at the time and she said that the graphics looked crap - lol
Very, very well put. Thanks for that. The only thing I'd adjust in your previous statement is that 'faith' (which is akin to a spiritual axiom) is something that I 'accept' as being true without definite solid proof.Then you have 'faith'. Faith is something you take to be true but you cannot prove or disprove it. You personally just 'know' it to be true.
Then, by all means ... do not ever take the RED Pill!I'm perfectly fine with a simulation.
Sure, PM it to me - did you use WPF, or Windows forms?I have a windows version written in C# if you are interested.