module MathRub

require 'rubmat/main'

Constants

EVALUE
MAX_INTEGER
PIVALUE

Public Class Methods

birds_eye(n, k) click to toggle source

NAME

Bird's Eye View v1.1.3

SYNOPSIS

Basic rep.s

DESCRIPTION

Bird's Eye View Procedure

# File lib/rubmat.rb, line 370
def self.birds_eye(n, k)
    return ((n-k)/(k+1));
end
combinatorial(glb, ksb) click to toggle source

NAME

Combinatorial Procedure v1.1.5

SYNOPSIS

combinatorial(glb, ksb) 'glb' represents is General mass of combinatorial approach 'klb' represents is Selection mass of combinatorial approach

DESCRIPTION

Combinatorial selection number of a input argument mass

# File lib/rubmat.rb, line 189
def self.combinatorial(glb, ksb)
    if(glb < ksb)
        raise RuntimeError.new("Global set cannot be greater than k-subsets")
    end
    sbst_given_size = factorial(glb)/(factorial(ksb)*factorial(glb-ksb)).to_f
    return sbst_given_size
end
dist_pres(presnum) click to toggle source

NAME

Distrubuting Presents Procedure v1.1.3

SYNOPSIS

dist_pres(presnum) 'presnum' value represents Present count.

DESCRIPTION

Use of Sequence of factorial and iterative_fact procedures for distributing presents.

# File lib/rubmat.rb, line 276
def self.dist_pres(presnum)
    return factorial(presnum)/iterative_fact(presnum);
end
eagle_view(m, t) click to toggle source

NAME

Eagle View v1.1.3

SYNOPSIS

Basic rep.s

DESCRIPTION

Eagle View Procedure

# File lib/rubmat.rb, line 384
def self.eagle_view(m, t)
    return (EVALUE**((t*t)/m));
end
factorial( n ) click to toggle source

NAME

Recursive Factorial Procedure Definition v1.1.3

SYNOPSIS

factorial(n) 'n' is the number which will calculated in procedure

DESCRIPTION

Iterative factorial definition

# File lib/rubmat.rb, line 68
def self.factorial( n )
    if (n <= 1)
        return 1
    else
        return n*factorial( n-1 ).to_i
    end
end
fermat_little(p, a) click to toggle source

NAME

Fermat's Little Theorem v1.1.3

SYNOPSIS

fermat_little(p, a)

DESCRIPTION

Fermat Little Theorem's Procedural Representation

(('WARNING'))((-Modular representation maybe couldn't evaluated-))

# File lib/rubmat.rb, line 450
def self.fermat_little(p, a)
  begin
    if(p%(ui_pow(a, (p-1))-1) == 0)
        return 0
    else
        return 1
    end
  end
rescue
  begin
    ArgumentError.new("High load. Terminated.")
  end
end
fib(n) click to toggle source

NAME

Recursive adding of procedure fibonacci

SYNOPSIS

fib(n) 'n' represents recursive definition

DESCRIPTION

Additive recursive definition of Fibonacci

# File lib/rubmat.rb, line 291
def self.fib(n)
    if (n <= 1) 
        return n;
    else
        return fib(n-1)+fib(n-2);
    end
end
help() click to toggle source

HELP

# File lib/rubmat.rb, line 11
  def self.help
puts "
Valid Commands
===============
help              Show this manpage
certain           Show certain conditions page
factorial         Recursive definition of factorial
                  'n' is the number which will calculated in procedure
binsearch         *binary => array
                  *size => binary array's size
                  *search_key => Compare string
                    *General values
                        *low => low value representation
                        *middle => middle value representation
                        *high => high value representation
birdseye          Bird's Eye View Procedure
combinatorial     'glb' represents is General mass of combinatorial approach
                  'klb' represents is Selection mass of combinatorial approach
distpres          'presnum' value represents Present count.
eagleview         Eagle View Procedure
fermatlittle      Fermat Little Theorem's Procedural Representation
fib               Additive recursive definition of Fibonacci
isprime           Is Prime Procedure
                  'nb' is the input argument number of procedure
iterativefact     Iterative factorial of procedural representation
sigma             Sigma procedure's simple procedure is rely on '(ax+b)^pw'
                  a represented by inta;
                  b represented by intb;
                  x represented by intx;
                  power represented by pw.
stirling          'strln' is the stirling number in stirling formula
subset            'zerosbst' variable, decision mechanism of zero subset is included or not included
                  'gen' is the general mass elements(objects) number
fibsum            Fibonacci Sum Procedure
twinprdx          Twin Paradox Lemma Solution Procedure
                  Selection mass represented by 'mass' value
uipow             Non-balanced power calculation procedure
"
end
is_prime(nb) click to toggle source

NAME

Is Prime Procedure v1.1.5

SYNOPSIS

is_prime(nb) 'nb' is the input argument number of procedure

DESCRIPTION

Is Prime Procedure

# File lib/rubmat.rb, line 420
def self.is_prime(nb)
    test = count = 0
    if (nb == 1)
        return -1
    end
    for i in 2..nb-1
        count++
        if (nb % i == 0)
            test = false
        end
    end
    if (!test)
        return 1
    else
        return 0
    end
end
iterative_fact(itrtnum) click to toggle source

NAME

Iterative Factorial Procedure v1.0.3

SYNOPSIS

Get input arguments from simple argument

DESCRIPTION

Iterative factorial of procedural representation

# File lib/rubmat.rb, line 113
def self.iterative_fact(itrtnum)
    itrtnum.downto(1) do
        total *= factorial(itrtnum)
    end
    return total
end
print_row(binary, size, low, mid, high) click to toggle source

NAME

Printing Row v1.5.5

SYNOPSIS

print_row(binary, size, low, mid, high) 'binary' represents binary array 'size' represents general size 'low' represents minimum value of binary array 'mid' represents middle value of binary array 'high' represents maximum value of binary array

DESCRIPTION

Underly array for printing.

run() click to toggle source
# File lib/rubmat.rb, line 501
def self.run
puts "===RubMat===
    Copyright (C) <2012>  <Mahmut Bulut>
    Type `help' for commands list
    and for distributing rules `certain'"
puts ""
begin
  command = ask(">=> ")
#command = commn.chomp!
  # Read arguments and defines commands
  # Will handle command line whitespaces
  
    if (command == 'help')
      puts help()
    end
    if (command == 'certain')
      puts "To see certain conditions please visit http://www.gnu.org/licenses/gpl-2.0.html#SEC3"
    end
    if (command == 'factorial')
      n = ask("Enter N value: ", Integer)
      puts factorial(n)
    end
    if (command == 'binsearch')
      begin
      binary = ask("Enter array name with [ & ] suffix: ")
      size = ask("Enter size of search range: ", Integer)
      search_key = ask("Enter search delimiter key", Integer)
      low = ask("Lower limit: ", Integer)
      middle = ask("Medium limit: ", Integer)
      high = ask("High limit: ", Integer)
      puts binary_search(binary, size, search_key, low, middle, high)
      rescue => error
        puts error
      end
    end
    if (command == 'birdseye')
      n = ask("Enter workspace mass number: ", Integer)
      k = ask("Enter selection mass number: ", Integer)
      puts birds_eye(n, k)
    end
    if (command == 'combinatorial')
      glb = ask("Enter global set objects number: ", Integer)
      ksb = ask("Enter k-subset objects number: ", Integer)
      puts combinatorial(glb, ksb)
    end
    if (command == 'distpres')
      presnum = ask("Present number: ", Integer)
      puts dist_pres(presnum)
    end
    if (command == 'eagleview')
      m = ask("Enter m value: ", Integer)
      t = ask("Enter t value: ", Integer)
      puts eagle_view(m, t)
    end
    if (command == 'fermatlittle')
      p = ans("Enter power number: ", Integer)
      a = ans("Enter base number:", Integer)
      puts fermat_little(p, a)
    end
    if (command == 'fib')
      n = ans("Enter the last incremental number: ", Integer)
      puts fib(n)
    end
    if (command == 'isprime')
      raise RuntimeError.new("Have some critical issues closed to next minor version")
#    nb = ask("Control number: ", Integer)
#    puts is_prime(nb)
    end
    if (command == 'iterativefact')
      begin
        itrtnum = ask("Enter the factorial input: ", Integer)
        throw :ball if (itrtnum >= MAX_INTEGER)
        puts iterative_fact(itrtnum)
      end
      catch(:ball) do
        raise ArgumentError.new("iterative factorial couldn't take this value's load. Terminated.")
      end
    end
    if (command == 'sigma')
      inta = ask("Enter a value: ", Integer)
      intx = ask("Enter x value: ", Integer)
      intb = ask("Enter b value: ", Integer)
      pw = ask("Enter power value: ", Integer)
      puts sigma(inta, intx, intb, pw)
    end
    if (command == 'stirling')
      begin
      strln = ask("Enter stirling procedure value: ", Integer)
      throw :glass if (strln >= MAX_INTEGER)
      puts stirling(strln)
      end
      catch(:glass) do
        raise ArgumentError.new("stirling couldn't take this value's load. Terminated.")
      end
    end
    if (command == 'subset')
      gen = ask("Enter mass objects number: ", Integer)
      zerosbst = agree("Include zero subset?")
      puts subset(gen, zerosbst)
    end
    if (command == 'fibsum')
      n = ask("Enter n value: ", Integer)
      puts sum_of_fib(n)
    end
    if (command == 'twinprdx')
      mass = ask("Enter mass number: ", Integer)
      puts twin_prdx(mass)
    end
    if (command == 'uipow')
      base = ask("Enter base value: ", Integer)
      exp = ask("Enter power value: ", Integer)
      puts ui_pow(base, exp)
    end
  end until(command == 'exit')
end
sigma(inta, intx, intb, pw) click to toggle source

NAME

Sigma Procedure v1.1.5

SYNOPSIS

sigma(inta, intx, intb, pw) Sigma procedure's simple procedure is rely on '(ax+b)^pw' a represented by inta; b represented by intb; x represented by intx; power represented by pw.

DESCRIPTION

'Sigma of the one unknowned equation' procedure

# File lib/rubmat.rb, line 213
def self.sigma(inta, intx, intb, pw)
    ttl = 0
    for i in 1..intx
        ttl += (inta*intx+intb)
    end
    if(pw == 1)
      return ttl
    end
    if(pw > 1)
        ttl=ui_pow(ttl, pw)
      return ttl
    end
    if(pw == 0)
      return 1
    end
end
stirling(strln) click to toggle source

NAME

Stirling Procedure v1.1.5

SYNOPSIS

stirling(strln) 'strln' is the stirling number in stirling formula

DESCRIPTION

Stirling Procedure for Stirling Lemma

# File lib/rubmat.rb, line 241
def self.stirling(strln)
  return (strln/constants1.EVALUE**strln)*Math.sqrt(2*constants1.PIVALUE*strln);
end
subset(gen, zerosbst) click to toggle source

NAME

Subset Procedure v1.1.3

SYNOPSIS

subset(gen, zerosbst) 'zerosbst' variable, decision mechanism of zero subset is included or not included 'gen' is the general mass elements(objects) number

DESCRIPTION

Calculate subset number of input arguments

# File lib/rubmat.rb, line 132
def self.subset(gen, zerosbst)
    main = case (zerosbst)
    when zerosbst == true
            rslt = ui_pow(2, gen) - 1
            return rslt
    when zerosbst == false
            rslt = ui_pow(2, gen)
            return rslt
    end
    return main
end
sum_of_fib(n) click to toggle source

NAME

Sum of Fibonacci Procedure v1.1.1

SYNOPSIS

sum_of_fib(n) 'n' is the number Basic reps

DESCRIPTION

Fibonacci Sum Procedure

# File lib/rubmat.rb, line 400
def self.sum_of_fib(n)
   return fib(n+2)-1;
end
to_bool() click to toggle source

NAME

to_bool v.0.0.1

SYNOPSIS

to_bool(void)

DESCRIPTION

to bool is convert integer valus to string boolean

# File lib/rubmat.rb, line 473
def self.to_bool
  if (self.to_bool == 1)
    puts "TRUE"
  elsif (self.to_bool == 0)
    puts "FALSE"
  elsif (self.to_bool == -1)
    puts "NaN"
  end
end
twin_prdx(mass) click to toggle source

NAME

Twin Paradox Lemma Solver v1.1.5

SYNOPSIS

twin_prdx(mass) Selection mass represented by 'mass' value

DESCRIPTION

Twin Paradox Lemma Solution Procedure

# File lib/rubmat.rb, line 256
def self.twin_prdx(mass)
    top=1
    for i in 366..366-mass
        top *= i
    end
    return top/ui_pow(366, mass)
end
ui_pow(base, exp) click to toggle source

NAME

Power procedure of two input arguments v2.1.3

SYNOPSIS

ui_pow(base, exp) 'base' argument is the base of power procedure 'exp' argument is the upscript of power procedure

DESCRIPTION

Wide representation of power procedure

# File lib/rubmat.rb, line 88
def self.ui_pow(base, exp)
    result = 1;
    while (exp)
        if (exp & 1)
            result *= base
        end
        exp >>= 1;
        base *= base
    end
    if(exp==0)
        result=base
    end
    return result
end