Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/ein16/synth/d2/obj_operator.py
ViewVC logotype

View of /branches/ein16/synth/d2/obj_operator.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3946 - (download) (as text) (annotate)
Sat Jun 11 00:39:19 2016 UTC (2 years, 9 months ago) by cchiw
File size: 1593 byte(s)
 added outer prod
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

class operator:
    def __init__(self, id, name, arity, symb):
        self.id=id
        self.name=name
        self.arity=arity
        self.symb=symb
    def toStr(self):
        self.name, str(arity)
    def get_name(self):
        return self.name
    def isEq_id(a,b):
        return (a.id==b.id)
    def isEq_idNum(a,b):
        return (a.id==b)

#------------------------------ constants -----------------------------------------------------
#  Constants
# id, name, arity, symbol
#unay operators
op_probe = operator(0,"probe", 1,"")
op_negation = operator(1,"neg", 1,"-")
op_gradient = operator(2,"grad", 1, u'∇')
op_divergence = operator(3,"div", 1, u'∇•')
op_curl= operator(4,"curl", 1, u'∇×')
op_jacob= operator(5,"jacob", 1, u'∇⊗')

op_unary = [op_probe, op_negation, op_gradient,op_divergence,op_curl,op_jacob]
#binary operators
op_add = operator(6,"addition", 2,"+")
op_subtract = operator(7,"subtraction", 2, "-")
op_cross = operator(8,"cross product", 2, u'×')
op_outer = operator(9,"outer product", 2, u'⊗')
op_inner = operator(10,"inner product", 2, u'•')
op_scale = operator(11,"multiplication", 2, u'*')



op_binary = [op_add, op_subtract, op_cross, op_outer, op_inner, op_scale]
#:,*,|()|,normalize,transpose,trace..

def idToStr(n):
    for i in  (op_unary+op_binary):
        if (n==i.id):
            return i.name
    return "no match"
def idToStrBinary(n):
    n =n+6
    for i in  (op_binary):
        if (n==i.id):
            return i.name
    else:
        return "no match"



root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0