fork download
  1. #!/usr/bin/Rscript
  2.  
  3. # Practical Limits.
  4. MAX_ABCD = 10000
  5. MAX_N = 20
  6.  
  7. # Generate (a, b, c, d) such that MAX >= a >= b >= c >= d >= 0.
  8. generate_abcd = function () { sort(runif(4, 0, MAX_ABCD), decreasing = TRUE) }
  9.  
  10. # Generate n such that MAX_N >= n >= 1.
  11. generate_n = function () { runif(1, 1, MAX_N) }
  12.  
  13. # TEST CONJECTURE: a^n - b^n + c^n - d^n >= (a - b + c - d)^n
  14. test = function (void) {
  15.  
  16. # Generate the parameters at random.
  17. n = generate_n()
  18. abcd = generate_abcd()
  19. a = abcd[1]
  20. b = abcd[2]
  21. c = abcd[3]
  22. d = abcd[4]
  23.  
  24. # Evaluate the expression in the conjecture.
  25. expr = a^n - b^n + c^n - d^n - (a - b + c - d)^n
  26.  
  27. # Print failure (if any).
  28. if (expr < 0) {
  29. print(paste("abcd:", a, b, c, d, "n:", n, "expr:", expr))
  30. }
  31.  
  32. # Result of test.
  33. ifelse ((expr >= 0), TRUE, FALSE)
  34. }
  35.  
  36. # Run multiple iterations of the test.
  37. MAX_ITER = 10000
  38. success = mean(sapply(1:MAX_ITER, test))
  39.  
  40. print(paste("Conjecture Success Percentage:", success * 100, "%"))
Success #stdin #stdout 1.74s 24464KB
stdin
Standard input is empty
stdout
[1] "Conjecture Success Percentage: 100 %"