Saturday 31 December 2016

Propositional Logic Evaluation in Python Update

In this post with continuation here, I've built a small Python library to work with Propositional Logic expressions. There are new functionalities, welcome post about them from Jupyter Notebook herecode on github updated. See you next year!!!

Friday 30 December 2016

Wednesday 28 December 2016

Automatic Differentiation Update

I added new functions to my Python automatic differentiation:  
power to dual number, natural logarithm, hiperbolic functions, exponential;  github and Jupyter Notebook updated.

Monday 19 December 2016

Python Data Structures Has New Members

Added new memebers to my python data structures family: Stack, Heap (min heap), Binary Tree, Binary Search Tree, Parse Tree (this is in fact parse tree building and evaluation algorithm).
Not much more work to have all the basic data structures implemented, I think just need graphs; hash tables are done well in python standart library, so don't need to repeat the job.  Code here.

Project Euler Helper

For Eulerians,  I've found in the internet file with some  Project Euler helping functions. I add a few my own and this is a file. Good Luck!

Sunday 18 December 2016

Python Automatic Differentiation

I've played with interesting concept of automatic differentiation and this is Jupiter notebook guest post about it. Code also here.

Wednesday 14 December 2016

Python Immutable Stack

While working on something bigger, I added new data structure to  python family, code on github.
Interface is based on my cons list, due to lack of TCO support in python this is not very useful - learning purposes or small datasets.

Sunday 11 December 2016

Python Immutable Trees

When I was building immutable python lists interface, I realized, than in the same way an immutable binary tree (or ternary and other) can be created - using python Abstract Base Class. Code looks like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Nil_tree:
    """class Nil_tree, the empty tree"""
    
    def is_empty(self):
        return True
    def left(self):
        return Exception("Empty")
    def right(self):
        return Exception("Empty")
    def __str__(self):
        return "()"
    
class Binary_tree:
    """Class Binary_tree, the non empty tree: ( val, left, right)"""
            
    def __init__(self, _item, _left, _right):
        self.item = _item
        self.left = _left
        self.right = _right
        
    def is_empty(self):
        return False


        
class Tree(metaclass=ABCMeta):
    
    @abstractmethod
    def is_empty():
        pass
    def item():
        pass
    def left():
        pass
    def right():
        pass
    
List.register(Nil_tree);
List.register(Binary_tree)

I would call it purely functional, can it be used in practice?  Maybe to do some functional stuff in python. This code plus some basic tree functions freely available on github.
PS I, also added lots of methods to cons lists, code here.

Wednesday 7 December 2016

Immutable Lists in Python

Surprisingly, when I open github and hit the search for "immutable lists python", it gave me only 2 not very interesting results. I'm working on materials in scheme (in the goal of write an interpreter and deep a bit into the  nlp), but I want do it in python, so I wrote my own implementation. It's similar to scala's, recursive lists.
Code  here. There is a few methods - so far works:)

Saturday 3 December 2016

Interesting Python Links

Here is a few, I think, worth checking links:
https://boltons.readthedocs.io/en/latest/debugutils.html
http://www.oreilly.com/programming/free/20-python-libraries-you-arent-using-but-should.csp
http://pybee.org/
https://automatetheboringstuff.com/
Enjoy!


Effective Overflow Testing (Bit Hacks II)

The post is in fact the second part of this. I reproduce from the book test for overflow in multiplication two  unsigned 32 bit integers, and extended it to unsigned longs (64 bit unsigned). The basic idea is to check sum  of leading zeroes (for 64 bits reasoning is the same) in 64 bit factors (when checking 32 bits). When the number is greater or equal than 32 (nlz(x) + nlz(y)) the multipliction does not overflow, when is less than 31 overflows; when equal to 31 is uncertain - additional checks are to be made.  
    Function is fast, there was no time difference when check run in a loop, precedding multiplication.
Code here (I'm moving from bitbucket, seems these days, everybody has github account from birthday-:)).