105
Fukuoka University of Education How to develop a mobile computer algebra system Mitsushi Fujimoto Fukuoka University of Education / Infty Project July 22, 2014 @ISSAC2014

PDF: Tutorial Handout

Embed Size (px)

Citation preview

Page 1: PDF: Tutorial Handout

Fukuoka University of Education

How to develop a mobile

computer algebra system

Mitsushi Fujimoto

Fukuoka University of Education / Infty Project

July 22, 2014 @ISSAC2014

Page 2: PDF: Tutorial Handout

Fukuoka University of Education

Plan of this tutorial

About Infty Project

Computer Algebra in Education

Porting a CAS to mobile devices

Making a GUI for some tablets

Further development

Application demo

Page 3: PDF: Tutorial Handout

Fukuoka University of Education

Infty Project

The beginning:

Started as a research project to help visually impaired

people in scientific fields in 1995.

Current research subjects:

Recognition and editing of math documents,

User interface, data conversion, etc.

Software

InftyReader / InftyEditor / ChattyInfty / AsirPad …

Active Members

10 people

Page 4: PDF: Tutorial Handout

InftyReader

Math OCR software

Page 5: PDF: Tutorial Handout

Fukuoka University of Education

InftyEditor

Mathematics Typesetting Tool for Windows

Three Input Methods for Math Expressions

Mouse / Keyboard / Tablet

Internal Data Format is XML

Export to LaTeX(PDF), MathML, HTML, Braill

codes and MS Word2010 are supported.

Computing functions for Math Expressions

Page 6: PDF: Tutorial Handout

AsirPad

A computer algebra system with

a Pen-based Interface on PDA

Page 7: PDF: Tutorial Handout

Fukuoka University of Education

Educational use of CAS

Lecture on RSA cryptography

At junior high school (Grade 8)

Handwriting is effective to input a

exponentiation.

Page 8: PDF: Tutorial Handout

Rubik’s cube solver using Gap

Page 9: PDF: Tutorial Handout

Fukuoka University of Education

Lecture on Rubik’s cube for visually

impaired students

Compute the order of operation and a

solution of Rubik’s cube using Gap

Page 10: PDF: Tutorial Handout

Fukuoka University of Education

CAS on tablets

CAS is effective and feasible in school

education.

Devices for learning demand

Portability

Quick power on/off

High resolution screen

Simple manipulation

→ Tablet devices are optimal.

CAS on tablets will be useful.

Page 11: PDF: Tutorial Handout

Fukuoka University of Education

Current Tablets / OS

iPad

iOS

Android tablets

Android

Windows tablets

Windows 8.1

Page 12: PDF: Tutorial Handout

Fukuoka University of Education

Use of CAS from Tablets

Method 1

Native application including CAS engine

Method 2

Access to CAS on the other machine through

an application on tablets

Method 3

Access to CAS on the other machine through

a Web browser on tablets

Method 4

Work sheet including CAS kernel

Page 13: PDF: Tutorial Handout

Fukuoka University of Education

CASs on tablets

Page 14: PDF: Tutorial Handout

Fukuoka University of Education

Features of our App

Target devices

Android / Windows tablets

Native App (Method 1)

CAS engine

Risa/Asir

Communication method with CAS engine

File I/O

GUI

Simple UI by Qt Quick

Page 15: PDF: Tutorial Handout

Mobile CAS for Windows

“Input field”

“Execute button”“Output area”

Page 16: PDF: Tutorial Handout

Mobile CAS for Android

Page 17: PDF: Tutorial Handout

Fukuoka University of Education

Porting a CAS engine

Page 18: PDF: Tutorial Handout

Fukuoka University of Education

Porting a CAS engine

A lot of CASs were designed for UNIX OS.

If the target device is a desktop PC, we

can use gcc/g++ on the PC.

Generally, Apps for tablets are developed

by cross-build environments on PC.

Google provides cross-build environments

Android SDK for Java

Android NDK for C/C++

Page 19: PDF: Tutorial Handout

Fukuoka University of Education

Arm rootfs + QEMU + chroot

C library of Android NDK is not glibc but

Bionic libc.

CAS needs some external libraries.

e.g., Garbage collector, GMP, etc

Some of them are not presumed to be built by

cross-build.

To avoid troublesome issues,

We use the cross-build environment by

Arm rootfs + QEMU + chroot.

Page 20: PDF: Tutorial Handout

Make Debian/arm in Debian/x86-64

Create arm rootfs in Linux box

Copy arm emulator QEMU to rootfs

Execute debootstrap again

$ sudo apt-get install debootstrap

$ mkdir armel_wheezy

$ sudo debootstrap --foreign --arch armel wheezy armel_wheezy

http://ftp.debian.org/debian/

$ sudo apt-get install qemu qemu-user-static

$ sudo cp /usr/bin/qemu-arm-static armel_wheezy/usr/bin/

$ sudo chroot armel_wheezy /debootstrap/debootstrap --second-stage

Page 21: PDF: Tutorial Handout

Fukuoka University of Education

Arm rootfs + QEMU + chroot

/├ home/| ├ fujimoto/| | ├ armel_wheezy/| | | ├ bin/| | | | └ qemu-arm-static| | | ├ boot/| | | ├ dev/| | | ├ etc/| | | ├ lib/| | | ├ proc/| | | ├ sys/| | | ├ tmp/| | | └ usr/

/├ bin/| └ qemu-arm-static├ boot/├ dev/├ etc/├ lib/├ proc/├ sys/├ tmp/└ usr/

Arm rootfs

chroot

Arm emulator

on x86-64

(User mode emulation)

Page 22: PDF: Tutorial Handout

Arm rootfs + QEMU + chroot

Install gcc/g++ in chroot environment

Modify a header file /usr/include/paths.h

in arm rootfs

Create a symbolic link

$ apt-get install build-essential m4 bison file

#if defined(ANDROID)

#define _PATH_BSHELL "/system/bin/sh"

#else

#define _PATH_BSHELL "/bin/sh"

#endif

$ mkdir -p /system/bin

$ ln -s /bin/sh /system/bin/sh

Page 23: PDF: Tutorial Handout

Build Risa/Asir for Android

$ sudo chroot ./armel_wheezy

# uname –m

armv7l

# cd /home/devel/asir2000

# export CFLAGS="-O2 -Wall -D ANDROID -fsigned-char -static"

# ./configure --prefix=/data/data/com.spartacusrex.spartacuside/files/local

# make

# make install

# make install-lib

# file ./asir

./asir: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically

linked, for GNU/Linux 2.6.26, not stripped

We can build source codes in this environment as if

we are in a self-build environment.

Page 24: PDF: Tutorial Handout

Execute Risa/Asir for Android

We can run Risa/Asir binary for Android on Linux box.

root@debian7:/home/devel/asir2000# ./asir

This is Risa/Asir, Version 20140224 (Kobe Distribution).

Copyright (C) 1994-2000, all rights reserved, FUJITSU

LABORATORIES LIMITED.

Copyright 2000-2007, Risa/Asir committers, http://www.openxm.org/.

GC 7.2 copyright 1988-2012, H-J. Boehm, A. J. Demers, Xerox, SGI,

HP.

PARI 2.0.17, copyright 1989-1999, C. Batut, K. Belabas, D. Bernardi,

H. Cohen and M. Olivier.

[0] fctr(x^3-1);

[[1,1],[x-1,1],[x^2+x+1,1]]

[1]

Page 25: PDF: Tutorial Handout

Risa/Asir on Android

Page 26: PDF: Tutorial Handout

Risa/Asir on Android

This binary and source codes is available

from http://www.fue.ac.jp/~fujimoto/asiroid/

Page 27: PDF: Tutorial Handout

Fukuoka University of Education

Creation of GUI for CAS

Page 28: PDF: Tutorial Handout

Fukuoka University of Education

Creation of GUI for CAS

Console based computer algebra systems

are useful as CAS engines.

Interaction with CAS engine through

terminal is inefficient.

→ We need GUI for CAS.

GUI should be developed by the method

not depending on platform.

WebView → Maxima on Android

QtQuick / Qt → AsirPad

Page 29: PDF: Tutorial Handout

Fukuoka University of Education

About Qt

A cross-platform application and UI

development framework

Target

Desktop – Windows / Linux / Mac OS X

Embedded – Windows Embedded /

Embedded Linux / QNX / VxWorks

Mobile – Android / iOS / Windows RT

Available language

C++ / QML

Page 30: PDF: Tutorial Handout

Fukuoka University of Education

About Qt

License

GPL v3

LGPL v2

Qt commercial license

Examples of Qt application

Google Earth

Skype

TeXworks

Photoshop Elements

Maya 2011

Page 31: PDF: Tutorial Handout

Fukuoka University of Education

About Qt

Trolltech(1994) -> Nokia(2008) -> Digia(2012)

Development environment

Qt Creator

Visual Studio Add-in

Current Version

Qt 5.3.1

Project URL

http://qt-project.org

Page 32: PDF: Tutorial Handout

Fukuoka University of Education

Requirements for Qt

1. Java SE Development Kit (JDK) v6 or later

2. Apache Ant v1.8 or later

3. Android NDK

4. Android SDK

5. Qt 5.3

Page 33: PDF: Tutorial Handout

Fukuoka University of Education

Construction develop environment

Let’s construct a development

environment on Windows x64.

We can develop on this environment

Windows 8 tablets Apps

Android tablets Apps

Page 34: PDF: Tutorial Handout

JDK 7

Page 35: PDF: Tutorial Handout

JDK 7

Page 36: PDF: Tutorial Handout

JDK 7

Page 37: PDF: Tutorial Handout

Apache Ant

Page 38: PDF: Tutorial Handout

Fukuoka University of Education

Apache Ant

Page 39: PDF: Tutorial Handout

Fukuoka University of Education

Apache Ant

Unpack the following file:

apache-ant-1.9.4-bin.zip

Copy the folder “apache-ant-1.9.4” to an

appropriate location (e.g. c:\android)

Page 40: PDF: Tutorial Handout

Android NDK

Page 41: PDF: Tutorial Handout

Android NDK

Page 42: PDF: Tutorial Handout

Fukuoka University of Education

Android NDK

Unpack the following file:

android-ndk-r9d-windows-x86_64.zip

Copy the folder “android-ndk-r9d” to an

appropriate location (e.g. c:\android)

Page 43: PDF: Tutorial Handout

Android SDK

Page 44: PDF: Tutorial Handout

Android SDK

Page 45: PDF: Tutorial Handout

Fukuoka University of Education

Android SDK

Unpack the following file:

adt-bundle-windows-x86_64-20140702.zip

Copy the following file and folder to an

appropriate location (e.g. c:\android)

SDK Manager.exe

sdk folder

Then,

Execute “SDK Manager.exe”

Page 46: PDF: Tutorial Handout

Android SDK

Page 47: PDF: Tutorial Handout

Android SDK

Page 48: PDF: Tutorial Handout

Android SDK

Page 49: PDF: Tutorial Handout

Android SDK

Page 50: PDF: Tutorial Handout

http://qt-project.org/

Page 51: PDF: Tutorial Handout

http://qt-project.org/

Page 52: PDF: Tutorial Handout
Page 53: PDF: Tutorial Handout

Execute

“qt-opensource-windows-x86-android-5.3.1.exe”

Page 54: PDF: Tutorial Handout

Qt Creator

Page 55: PDF: Tutorial Handout

Tool -> Options

Page 56: PDF: Tutorial Handout

Fukuoka University of Education

Connecting your Physical Android

Device to Windows

Page 57: PDF: Tutorial Handout
Page 58: PDF: Tutorial Handout

Fukuoka University of Education

Connect to Windows

Page 59: PDF: Tutorial Handout

Connect to Windows

Page 60: PDF: Tutorial Handout

Fukuoka University of Education

Connecting Nexus7

Page 61: PDF: Tutorial Handout

Fukuoka University of Education

How to develop Qt App

Page 62: PDF: Tutorial Handout

Fukuoka University of Education

How to develop Qt App

1. Creating a GUI by QML

QML is CSS/JavaScript like language.

2. Creating C++ plugins for QML

Calling external program

Setting environment variables

File I/O

3. Importing C++ plugins in QML

Let’s make a Qt App calling CAS engine.

Page 63: PDF: Tutorial Handout

Fukuoka University of Education

Creating a GUI by QML

1. Create a project folder in c:\android

e.g. projects

2. Execute Qt Creator

Page 64: PDF: Tutorial Handout
Page 65: PDF: Tutorial Handout

Input

Name: MobileCAS

Create in: c:\android\projects

Page 66: PDF: Tutorial Handout

Select

Qt Quick component set: Qt Quick Controls 1.1

Page 67: PDF: Tutorial Handout
Page 68: PDF: Tutorial Handout
Page 69: PDF: Tutorial Handout

“Mobile CAS”

1000

700

Page 70: PDF: Tutorial Handout
Page 71: PDF: Tutorial Handout
Page 72: PDF: Tutorial Handout
Page 73: PDF: Tutorial Handout

Build

Run

Page 74: PDF: Tutorial Handout
Page 75: PDF: Tutorial Handout

Fukuoka University of Education

Execute an external program

MobileCAS executes an external CAS

engine.

QML has no function to access external

programs.

We make a C++ plugin to execute external

programs.

Page 76: PDF: Tutorial Handout

File -> New File or Project

Page 77: PDF: Tutorial Handout

Fukuoka University of Education

Input

Name: cmdlaunch

Create in: c:\android\projects

Page 78: PDF: Tutorial Handout
Page 79: PDF: Tutorial Handout

Input

Object class-name: Launcher

URI: org.inftyproject.launcher

Page 80: PDF: Tutorial Handout
Page 81: PDF: Tutorial Handout

launch.h

This code is available from

http://askubuntu.com/questions/288494/run-system-commands-from-qml-app

Page 82: PDF: Tutorial Handout

launcher.cpp

This code is available from

http://askubuntu.com/questions/288494/run-system-commands-from-qml-app

Page 83: PDF: Tutorial Handout

Build

Build Windows plugin

Page 84: PDF: Tutorial Handout

Build

Build Android plugin

Page 85: PDF: Tutorial Handout

The following error occurs:

Delete the following lines in the

“cmdlaunch.pro”

Build Android plugin

Page 86: PDF: Tutorial Handout

Fukuoka University of Education

Install plugin

Windows

Copy

c:\android\project\cmdlaunch\qmldir

c:\android\project\build-cmdlaunch-

Desktop_Qt_5_3_MinGW_32bit-Debug\

debug\cmdlaunch.dll

to

c:\Qt\Qt5.3.1\5.3\mingw482_32\qml\org\

inftyproject\launcher\

Page 87: PDF: Tutorial Handout

Fukuoka University of Education

Importing C++ plugins in QML

Add

Launcher

element

Page 88: PDF: Tutorial Handout

Fukuoka University of Education

Importing C++ plugins in QML

Page 89: PDF: Tutorial Handout

Fukuoka University of Education

MobileCAS: Build -> Run

Input “notepad” in the textfield

Click “Execute” button

Notepad will appear

Page 90: PDF: Tutorial Handout

Fukuoka University of Education

Install plugin

Android

Copy

c:\android\project\cmdlaunch\qmldir

c:\android\project\build-cmdlaunch-

Android_for_armeabi_GCC_4_8_Qt_5_3_1-

Debug\libcmdlaunch.so

to

c:\Qt\Qt5.3.1\5.3\android_armv5\qml\org\

inftyproject\launcher\

Page 91: PDF: Tutorial Handout

Fukuoka University of Education

Set PATH, File I/O plugin

These C++ plugins are available from:

http://www.inftyproject.org/ISSAC2014/

• For Windows

• Extract windows_plugins.zip, and copy “org”

to c:\Qt\Qt5.3.1\5.3\mingw482_32\qml\

• For Android

• Extract android_plugins.zip, and copy “org”

to c:\Qt\Qt5.3.1\5.3\android_armv5\qml\

Page 92: PDF: Tutorial Handout

Fukuoka University of Education

Copy CAS engine for Windows

Download asirwin.zip from:

http://www.inftyproject.org/ISSAC2014/

Extract it, and copy all files including asir.exe

to c:\android\project\build-MobileCAS-

Desktop_Qt_5_3_MinGW_32bit-Debug\

Page 93: PDF: Tutorial Handout

Add

elements

Page 94: PDF: Tutorial Handout

main.qml for Windows

Create input file

Execute Asir

Get result

Page 95: PDF: Tutorial Handout

Input command

for Risa/AsirClick

Computation result

Page 96: PDF: Tutorial Handout

Fukuoka University of Education

Copy CAS engine to Android

1. Install Terminal IDE to your Android device

through Google Play.

2. Click 'Install System' in the menu of Terminal

IDE.

3. Download and install Risa/Asir on Terminal IDE:

$ wget http://133.81.157.19/~fujimoto/android/

asiroid.tar.gz

$ tar zxvf asiroid.tar.gz

$ chmod –R 755 local

Page 97: PDF: Tutorial Handout

Fukuoka University of Education

Copy CAS engine to Android

4. Execute the following on Terminal IDE:

$ install_gcc

$ chmod –R 755 android-gcc-4.4.0

$ mkdir bin

$ cd bin

$ ln -s ../android-gcc-4.4.0/bin/arm-eabi-cpp cpp

$ ln -s ../local/lib/asir/asir asir

$ cd ..

$ chmod –R 755 bin

5. Run asir to check this installation

$ fep asir

Page 98: PDF: Tutorial Handout

main.qml for Android

.

.

.

Page 99: PDF: Tutorial Handout

main.qml for Android

Page 100: PDF: Tutorial Handout

Fukuoka University of Education

Screenshot on Android

Page 101: PDF: Tutorial Handout

Computing Process of Mobile CAS

GUI

Risa/Asir

/data/data/com.spartacusrex

.spartacuside/files/bin/

/data/data/org.qtproject.example.MobileCAS/

/sdcard/tmp/

input.txt

output.txt

Page 102: PDF: Tutorial Handout

Fukuoka University of Education

Further development

Communication with CAS engine

OpenXM

A communication protocol on TCP/IP sockets

Client Server Model

Inputting math expressions

Handwriting interface of InftyEditor

Importing Infty handwriting recognition algorithm

written by C++

Math font for Qt

Infty Math fonts

Page 103: PDF: Tutorial Handout

AsirPad for Windows

Page 104: PDF: Tutorial Handout

AsirPad for Android

Page 105: PDF: Tutorial Handout

Fukuoka University of Education

Conclusion

We explained an implementation method

of a computer algebra system for tablets.

Building a CAS engine

Arm rootfs + QEMU + chroot

Creation of GUI

Qt Quick

C++ plugin

This method is available for developing

cross-platform computer algebra Apps.