Last update March 7, 2012

Dwith Swig / Examples /
Gi Na C



Difference (last change) (no other diffs, normal page display)

Deleted: 154,264d153
jam tangan
jam tangan murah
jam tangan kw
hostgator coupon
kata mutiara
Jasa SEO
EZido
RDAnet
pioneer deh-1300mp
asus a53e-xa2
asus tf101-b1
asus tf101-a1
asus n53sv-eh72
asus republic of gamers g74sx
asus acer a5250
acer chromebook ac700
asus asus 53u
lg infinia 55lw5600
Sonicview 360 premier
asus 7 cu ft freezer
asus 30 single wall oven
brother cs6000i sewing machine
brother 1034d serger
brother sewing machines
Yokohama Geolandar H/T-S
crib tent tots in mind
kidco peapod plus
foscam fi8910w
samsung pl120 review
gopro helmet cam
Canon SX130IS
powershot s100
ContourHD 1080p
canon vixia hf r21
digital picture frame
canon ef 50mm f1.4
canon ef 70-300mm review
wide angle lenses
moving comfort sports bra
moving comfort bra
womens argyle sweater
bebe dresses
ViewSonic VX2250WM
Le Pan TC 970
Apple MacBook Air MC965LL
Sennheiser CX 880
plantronics cs540
ultrasonic jewelry cleaner
Sennheiser RS120
bose quietcomfort 15 acoustic noise cancelling headphones
logitech harmony one remote
logitech harmony 900
sony mhc-ec69i
sony mhcec909ip
bose wave music system
sony htss380
logitech squeezebox touch
sony dvp-fx970
onkyo tx-nr509
onkyo tx - nr609
onkyo ht-s3400
energy 5.1 take classic home theater system
polk audio psw505
onkyo ht-s5400
onkyo tx-nr709
belkin pf60
onkyo ht-rc360
denon avr-1912
Yamaha YHT-S400BL
fujitsu scansnap s1500
brother hl-2270dw
epson workforce 545
hp laserjet p2055dn
bushnell 8mp trophy cam
toshiba 32c110u
panasonic viera tc-p60s30
VIZIO E220VA
hauppauge wintv dcr-2650
Acer AM3970-U5022
Acer AspireRevo AR3700-U3002
Dell Inspiron i570
Dell GX620
Gateway FX6860-UR20P
Western Digital My Passport Essential SE 1 TB USB 3.0
Fujitsu ScanSnap S1300
Epson Perfection V300
Fujitsu SCANSNAP S1100
NeatDesk Desktop Scanner and Digital Filing System
Epson WorkForce Pro GT-S50
Kodak P811BK
Epson Perfection V330
Viewsonic VX2453MH
Asus VE228H
ViewSonic VA2431WM
Samsung B2230
HP 2711x
ASUS ML228H
Epson PowerLite Home Cinema 8350
Optoma PK301
Epson EX7210
Epson EX5210
ViewSonic PJD5133
Acer X1161P
FAVI RioHD-LED-2
Epson EX3210
ViewSonic PJD6531w
Trinity 360 Breville 800JEXL
Skil 3320-02
Delta 46-460
Grizzly G0555
Delta 18-900L

Table of contents of this page
C++ classes for symbolic manipulation   
Features used   
Code to be wrapped   
Interface file   
Run SWIG   
Example application   
Compile and Link   
Output   

C++ classes for symbolic manipulation    

The classes provided by GiNaC allow for symbolic expressions to be expressed and manipulated.

There are three classes provided in GiNaC which made are available in D using SWIG.

  • symbol is an object initialised to a string. e.g.
symbol x = new symbol("x");
symbol y = new symbol("y");

  • ex is an expression involving one or more symbols. e.g.
ex exx = new ex(x);
ex exy = new ex(y);

  • lst is a list of expressions. e.g.
lst l = new lst(exx,exy);

An object of class lst can be used to initalise an expression from a string e.g.

ex e11 = new ex("x+y",l);

where l provides a list of the symbols in the expression.

Features used    

The features used here are the same as described in /Examples/Qdmath . The interface contains a lot of code to implement overloaded operators. The implementation of this in D is considerably easier than some other languages, such as Ruby and python.

Code to be wrapped    

This is contained in the header files for GiNaC. The current version uses GiNaC 1.1.4. This needs to be upadated to the current version.

Interface file    

This is rather long so I will not put it here. It is getting more urgent to set up a location for distribution of these files to those who would like them. It was not a long task to adapt the interface file which I already used for Ruby.

Run SWIG    

swig -dmd -c++ ginacd.i

The output is the following files

  • ginacd.d
  • classsymbol.d
  • classex.d
  • classlst.d
  • ginacdPINVOKE.d
  • ginacd_wrap.cxx

Example application    

runginacd.d

// Experiments with GiNaC for D..

// Imports conversion stuff from C
import std.string;
import std.intrinsic;
import std.math;

import classsymbol;

int main(char[][] args)
{
    printf("GiNaC for D\n");
    symbol x = new symbol("x");
    printf("x = %s\n",x.str());
    symbol y = new symbol("y");
    printf("y = %s\n",y.str());
    ex exx = new ex(x);
    ex exy = new ex(y);
    lst l  = new lst(exx,exy);
    printf("l = %s\n",l.str());
    ex e0 = new ex(0);
    ex e1 = new ex(1);
    printf("e1 = %s\n",e1.str());
    ex e11 = new ex("x+y",l);
    printf("e11 = %s\n",e11.str());
    printf("e1 + e11 = %s\n",(e1+e11).str());
    printf("e11 - e1 = %s\n",(e11-e1).str());
    printf("e11 * e11 = %s\n",(e11*e11).str());
    printf("e11 / e11 = %s\n",(e11/e11).str());
    printf("x + y = %s\n",(x+y).str());
    printf("e1 + y = %s\n",(e1+y).str());
    printf("x + e1 = %s\n",(x+e1).str());
    printf("1 + e11 = %s\n",(1+e11).str());
    printf("1.5 + e11 = %s\n",(1.5+e11).str());
    printf("2*x + 3*y = %s\n",(2*x+3*y).str());
    ex es = 1 + 3*x/(x+y);
    printf("es = 1 + 3*x/(x+y) = %s\n",es.str());
    printf("es.normal() = %s\n",es.normal().str());

    printf("End of tests\n");
    return 0;
}

Compile and Link    

Linux

dmd -c runginacd.d
dmd -c ginacd.d
dmd -c classsymbol.d
dmd -c classex.d
dmd -c classlst.d
g++ -c ginacd_wrap.cxx
g++ runginacd.o -orunginacd ginacd.o classsymbol.o classex.o classlst.o ginacd_wrap.o -lginac -lphobos -lpthread -lm

Windows

GiNaC is not available for Windows.

Output    

GiNaC for D
x = x
y = y
l = {x,y}
e1 = 1
e11 = y+x
e1 + e11 = 1+y+x
e11 - e1 = -1+y+x
e11 * e11 = (y+x)^2
e11 / e11 = 1
x + y = y+x
e1 + y = 1+y
x + e1 = 1+x
1 + e11 = 1+y+x
1.5 + e11 = 1.5+y+x
2*x + 3*y = 3*y+2*x
es = 1 + 3*x/(x+y) = 1+3*(y+x)^(-1)*x
es.normal() = (y+x)^(-1)*(y+4*x)
End of tests


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: March 7, 2012 20:27 (diff))