├── src ├── tests │ ├── files │ │ ├── nodes │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── additional │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── beautify │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── complexity │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── expansion │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── exponential │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── simplest │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── u_der.txt │ │ ├── simplification │ │ │ ├── u_der.txt │ │ │ ├── irr_num.txt │ │ │ ├── u_ops.txt │ │ │ └── bin_ops.txt │ │ ├── irr_num.txt │ │ ├── u_ops.txt │ │ └── bin_ops.txt │ ├── specific │ │ ├── LiteralTest.java │ │ ├── RawValueTest.java │ │ ├── MathContextTest.java │ │ ├── GraphTest.java │ │ ├── BinaryOperationTest.java │ │ ├── CustomOperationTest.java │ │ ├── FractionTest.java │ │ ├── NodeTest.java │ │ └── UnaryOperationTest.java │ ├── TestPrint.java │ ├── cas │ │ ├── Benchmark.java │ │ ├── CasExpansionTest.java │ │ ├── CasSimplificationTest.java │ │ ├── FirstDerivativeTest.java │ │ └── CasComprehensiveTest.java │ └── SpeedTest.java ├── jui │ ├── Canvas.java │ ├── Chart.java │ ├── ItemBar.java │ ├── Controllable.java │ ├── VItemBar.java │ ├── MenuBar.java │ ├── HChart.java │ ├── VChart.java │ ├── HItemBar.java │ ├── bundles │ │ ├── ValueCollector.java │ │ ├── EnumSelector.java │ │ └── ProgressIndicator.java │ ├── Scalable.java │ ├── Image.java │ ├── KeyControl.java │ ├── MouseControl.java │ ├── Mode.java │ ├── Event.java │ ├── customization │ │ ├── tardis_blue │ │ ├── theme_blue │ │ ├── random │ │ └── default │ ├── SpaceHolder.java │ ├── EventListener.java │ ├── Label.java │ ├── Switch.java │ ├── TextField.java │ ├── Button.java │ ├── HSlider.java │ ├── VSlider.java │ ├── MenuItem.java │ └── ProgressBar.java ├── jas │ ├── core │ │ ├── Nameable.java │ │ ├── Evaluable.java │ │ ├── BinLeafNode.java │ │ ├── Calculus.java │ │ ├── JASException.java │ │ ├── operations │ │ │ ├── Manipulable.java │ │ │ ├── Argument.java │ │ │ ├── Manipulation.java │ │ │ └── Signature.java │ │ ├── Mode.java │ │ ├── LeafNode.java │ │ ├── Assets.java │ │ └── components │ │ │ ├── Literal.java │ │ │ ├── Variable.java │ │ │ ├── Constants.java │ │ │ ├── RawValue.java │ │ │ ├── Matrix.java │ │ │ └── Vector.java │ ├── utils │ │ ├── Timer.java │ │ ├── AnsiColor.java │ │ ├── Utils.java │ │ └── ColorFormatter.java │ ├── graph │ │ ├── SuppliedVar.java │ │ ├── Point.java │ │ └── Range.java │ ├── extras │ │ └── Element.java │ └── Function.java ├── CasCmdline.java ├── CasController.java └── CAS.java ├── libs ├── core.jar ├── jogl-all.jar ├── gluegen-rt.jar ├── jogl-all-natives-linux-i586.jar ├── gluegen-rt-natives-linux-i586.jar ├── jogl-all-natives-linux-amd64.jar ├── jogl-all-natives-windows-i586.jar ├── gluegen-rt-natives-linux-amd64.jar ├── gluegen-rt-natives-linux-armv6hf.jar ├── gluegen-rt-natives-windows-amd64.jar ├── gluegen-rt-natives-windows-i586.jar ├── jogl-all-natives-linux-armv6hf.jar ├── jogl-all-natives-windows-amd64.jar ├── jogl-all-natives-macosx-universal.jar └── gluegen-rt-natives-macosx-universal.jar ├── .gitignore ├── misc └── screenshots │ └── jas_simple_ui.png └── LICENSE /src/tests/files/nodes/u_der.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/tests/files/additional/u_der.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/tests/files/beautify/u_der.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/tests/files/complexity/u_der.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/tests/files/expansion/u_der.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/tests/files/exponential/u_der.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/tests/files/simplest/u_der.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/jui/Canvas.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | public class Canvas { 4 | } 5 | -------------------------------------------------------------------------------- /src/jui/Chart.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | public abstract class Chart { 4 | } 5 | -------------------------------------------------------------------------------- /src/jui/ItemBar.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | public class ItemBar{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /libs/core.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/core.jar -------------------------------------------------------------------------------- /src/jui/Controllable.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | public interface Controllable { 4 | 5 | } -------------------------------------------------------------------------------- /libs/jogl-all.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/jogl-all.jar -------------------------------------------------------------------------------- /libs/gluegen-rt.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/gluegen-rt.jar -------------------------------------------------------------------------------- /src/jui/VItemBar.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | public class VItemBar extends ItemBar{ 4 | VItemBar(){ 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .idea/* 3 | hs_err* 4 | out 5 | out/* 6 | .DS_Store 7 | */.DS_Store 8 | lib 9 | lib/* 10 | 11 | -------------------------------------------------------------------------------- /src/jui/MenuBar.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 28/01/2017. 5 | */ 6 | public class MenuBar { 7 | } 8 | -------------------------------------------------------------------------------- /libs/jogl-all-natives-linux-i586.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/jogl-all-natives-linux-i586.jar -------------------------------------------------------------------------------- /misc/screenshots/jas_simple_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/misc/screenshots/jas_simple_ui.png -------------------------------------------------------------------------------- /libs/gluegen-rt-natives-linux-i586.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/gluegen-rt-natives-linux-i586.jar -------------------------------------------------------------------------------- /libs/jogl-all-natives-linux-amd64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/jogl-all-natives-linux-amd64.jar -------------------------------------------------------------------------------- /libs/jogl-all-natives-windows-i586.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/jogl-all-natives-windows-i586.jar -------------------------------------------------------------------------------- /libs/gluegen-rt-natives-linux-amd64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/gluegen-rt-natives-linux-amd64.jar -------------------------------------------------------------------------------- /libs/gluegen-rt-natives-linux-armv6hf.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/gluegen-rt-natives-linux-armv6hf.jar -------------------------------------------------------------------------------- /libs/gluegen-rt-natives-windows-amd64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/gluegen-rt-natives-windows-amd64.jar -------------------------------------------------------------------------------- /libs/gluegen-rt-natives-windows-i586.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/gluegen-rt-natives-windows-i586.jar -------------------------------------------------------------------------------- /libs/jogl-all-natives-linux-armv6hf.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/jogl-all-natives-linux-armv6hf.jar -------------------------------------------------------------------------------- /libs/jogl-all-natives-windows-amd64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/jogl-all-natives-windows-amd64.jar -------------------------------------------------------------------------------- /src/jui/HChart.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 28/01/2017. 5 | */ 6 | public class HChart extends Chart { 7 | } 8 | -------------------------------------------------------------------------------- /src/jui/VChart.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 28/01/2017. 5 | */ 6 | public class VChart extends Chart { 7 | } 8 | -------------------------------------------------------------------------------- /libs/jogl-all-natives-macosx-universal.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/jogl-all-natives-macosx-universal.jar -------------------------------------------------------------------------------- /src/jui/HItemBar.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 28/01/2017. 5 | */ 6 | public class HItemBar extends ItemBar { 7 | } 8 | -------------------------------------------------------------------------------- /libs/gluegen-rt-natives-macosx-universal.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JiachenRen/java-algebra-system/HEAD/libs/gluegen-rt-natives-macosx-universal.jar -------------------------------------------------------------------------------- /src/jui/bundles/ValueCollector.java: -------------------------------------------------------------------------------- 1 | package jui.bundles; 2 | 3 | /** 4 | * This class is used to manage multiple color Selectors 5 | */ 6 | public class ValueCollector { 7 | } 8 | -------------------------------------------------------------------------------- /src/jui/Scalable.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 29/04/2017. 5 | */ 6 | public interface Scalable { 7 | Displayable setScalingFactor(float scale); 8 | } 9 | -------------------------------------------------------------------------------- /src/jas/core/Nameable.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | /** 4 | * Created by Jiachen on 3/15/18. 5 | * Nameable 6 | */ 7 | public interface Nameable { 8 | String getName(); 9 | } 10 | -------------------------------------------------------------------------------- /src/jas/core/Evaluable.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | /** 4 | * Created by Jiachen on 20/05/2017. 5 | * Evaluable 6 | */ 7 | public interface Evaluable { 8 | double eval(double x); 9 | } 10 | -------------------------------------------------------------------------------- /src/jui/Image.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /*created Jan 26th.*/ 4 | /*this is now effectively the newest version of JUI, modified April 22th, 2017*/ 5 | public class Image /*extends Displayable*/ { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/jas/core/BinLeafNode.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | /** 4 | * Created by Jiachen on 3/4/18. 5 | * BinLeafNode: classes that are not BinaryOperations. Just a tag. 6 | */ 7 | public interface BinLeafNode { 8 | } 9 | -------------------------------------------------------------------------------- /src/jui/KeyControl.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 30/04/2017. 5 | */ 6 | public interface KeyControl extends Controllable{ 7 | public void keyPressed(); 8 | 9 | public void keyReleased(); 10 | } 11 | -------------------------------------------------------------------------------- /src/jas/core/Calculus.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | /** 4 | * Created by Jiachen on 3/17/18. 5 | * Calculus 6 | */ 7 | public class Calculus { 8 | public static final String DERIVATIVE = "derivative"; 9 | public static final String SUM = "sum"; 10 | } 11 | -------------------------------------------------------------------------------- /src/jas/core/JASException.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | /** 4 | * Created by Jiachen on 3/10/18. 5 | * JMC Exception 6 | */ 7 | public class JASException extends RuntimeException { 8 | public JASException(String msg) { 9 | super(msg); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/jas/core/operations/Manipulable.java: -------------------------------------------------------------------------------- 1 | package jas.core.operations; 2 | 3 | import jas.core.Node; 4 | 5 | import java.util.ArrayList; 6 | 7 | /** 8 | * Created by Jiachen on 3/17/18. 9 | * Manipulable 10 | */ 11 | public interface Manipulable { 12 | Node manipulate(ArrayList operands); 13 | } 14 | -------------------------------------------------------------------------------- /src/jui/MouseControl.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 30/04/2017. 5 | */ 6 | public interface MouseControl extends Controllable { 7 | boolean isMouseOver(); 8 | 9 | void mouseReleased(); 10 | 11 | void mousePressed(); 12 | 13 | void mouseDragged(); 14 | 15 | void mouseWheel(); 16 | } 17 | -------------------------------------------------------------------------------- /src/jui/Mode.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Style Control for background/contour/text color 5 | */ 6 | public enum Mode { 7 | CONSTANT(0), VOLATILE(1), DISABLED(2); 8 | private int val; 9 | 10 | Mode(int i) { 11 | val = i; 12 | } 13 | 14 | public int getValue() { 15 | return val; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/jui/Event.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 30/04/2017. 5 | */ 6 | public enum Event { 7 | KEY_PRESSED, 8 | KEY_RELEASED, 9 | KEY_HELD, 10 | MOUSE_PRESSED, 11 | MOUSE_RELEASED, 12 | MOUSE_OVER, 13 | MOUSE_ENTERED, 14 | MOUSE_LEFT, 15 | MOUSE_WHEEL, 16 | MOUSE_DRAGGED, 17 | MOUSE_HELD,//TODO 18 | MOUSE_CLICKED, //TODO 19 | CONTENT_CHANGED, 20 | } 21 | -------------------------------------------------------------------------------- /src/tests/specific/LiteralTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.core.Compiler; 4 | import jas.core.components.Literal; 5 | 6 | import static tests.TestPrint.*; 7 | 8 | /** 9 | * Created by Jiachen on 3/23/18. 10 | * Literal Test 11 | */ 12 | public class LiteralTest { 13 | public static void main(String args[]){ 14 | l(Compiler.compile("('heef'+x)^2*a").expand().simplify()); 15 | l(new Literal("hello")); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/tests/files/u_der.txt: -------------------------------------------------------------------------------- 1 | cos(5) 2 | sin(5) 3 | ln(5) 4 | log(5) 5 | acos(5) 6 | asin(5) 7 | tan(5) 8 | atan(5) 9 | abs(5) 10 | csc(5) 11 | sec(5) 12 | cot(5) 13 | cosh(5) 14 | sinh(5) 15 | tanh(5) 16 | cos(a) 17 | sin(a) 18 | ln(a) 19 | log(a) 20 | acos(a) 21 | asin(a) 22 | tan(a) 23 | atan(a) 24 | abs(a) 25 | csc(a) 26 | sec(a) 27 | cot(a) 28 | cosh(a) 29 | sinh(a) 30 | tanh(a) 31 | cos(x) 32 | sin(x) 33 | ln(x) 34 | log(x) 35 | acos(x) 36 | asin(x) 37 | tan(x) 38 | atan(x) 39 | abs(x) 40 | csc(x) 41 | sec(x) 42 | cot(x) 43 | cosh(x) 44 | sinh(x) 45 | tanh(x) -------------------------------------------------------------------------------- /src/tests/files/simplification/u_der.txt: -------------------------------------------------------------------------------- 1 | cos(5) 2 | sin(5) 3 | ln(5) 4 | log(5) 5 | acos(5) 6 | asin(5) 7 | tan(5) 8 | atan(5) 9 | abs(5) 10 | csc(5) 11 | sec(5) 12 | cot(5) 13 | cosh(5) 14 | sinh(5) 15 | tanh(5) 16 | cos(a) 17 | sin(a) 18 | ln(a) 19 | log(a) 20 | acos(a) 21 | asin(a) 22 | tan(a) 23 | atan(a) 24 | abs(a) 25 | csc(a) 26 | sec(a) 27 | cot(a) 28 | cosh(a) 29 | sinh(a) 30 | tanh(a) 31 | cos(x) 32 | sin(x) 33 | ln(x) 34 | log(x) 35 | acos(x) 36 | asin(x) 37 | tan(x) 38 | atan(x) 39 | abs(x) 40 | csc(x) 41 | sec(x) 42 | cot(x) 43 | cosh(x) 44 | sinh(x) 45 | tanh(x) -------------------------------------------------------------------------------- /src/jas/utils/Timer.java: -------------------------------------------------------------------------------- 1 | package jas.utils; 2 | 3 | /** 4 | * Created by Jiachen on 3/24/18. 5 | * Timer 6 | */ 7 | public class Timer { 8 | private long time; 9 | 10 | public Timer() { 11 | reset(); 12 | } 13 | 14 | public void reset() { 15 | time = current(); 16 | } 17 | 18 | private long current() { 19 | return System.currentTimeMillis(); 20 | } 21 | 22 | public long millis() { 23 | return current() - time; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return millis() + " ms"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/tests/TestPrint.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | /** 4 | * Created by Jiachen on 3/7/18. 5 | * Test printing methods. 6 | */ 7 | public class TestPrint { 8 | public static boolean DISABLED = false; 9 | 10 | public static void l(Object... objects) { 11 | for (Object o : objects) { 12 | l(o); 13 | } 14 | } 15 | 16 | public static void l(Object o) { 17 | if (DISABLED) return; 18 | System.out.println(o); 19 | } 20 | 21 | public static void p(Object o) { 22 | if (DISABLED) return; 23 | System.out.print(o); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/jui/customization/tardis_blue: -------------------------------------------------------------------------------- 1 | color_mode: RGB 2 | 3 | container_margin_x: 3 4 | container_margin_y: 3 5 | container_spacing: 3 6 | 7 | container_visible: false 8 | display_contour: false 9 | rounded: true 10 | 11 | contour_thickness: 1 12 | rounding: 3 13 | font_scalar: 1.5f 14 | 15 | background_color: 50,50,50,50 16 | mouse_pressed_background_color: 50,255,100,180 17 | mouse_over_background_color: 16,35,114,255 18 | 19 | contour_color: 0,0,0,255 20 | mouse_pressed_contour_color: 0,0,0,255 21 | mouse_over_contour_color: 0,0,0,255 22 | 23 | text_color: 0,0,0,255 24 | mouse_pressed_text_color: 0,0,0,255 25 | mouse_over_text_color: 0,0,0,255 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/jui/customization/theme_blue: -------------------------------------------------------------------------------- 1 | color_mode: RGB 2 | 3 | container_margin_x: 3 4 | container_margin_y: 3 5 | container_spacing: 3 6 | 7 | container_visible: false 8 | display_contour: false 9 | rounded: true 10 | 11 | contour_thickness: 1 12 | rounding: 3 13 | font_scalar: 1.5f 14 | 15 | background_color: 50,50,70,50 16 | mouse_pressed_background_color: 50,100,255,180 17 | mouse_over_background_color: 50,100,200,220 18 | 19 | contour_color: 0,0,0,255 20 | mouse_pressed_contour_color: 0,0,0,255 21 | mouse_over_contour_color: 0,0,0,255 22 | 23 | text_color: 0,0,0,255 24 | mouse_pressed_text_color: 0,0,0,255 25 | mouse_over_text_color: 20,255,255,255 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/jui/SpaceHolder.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 26/04/2017. 5 | */ 6 | public class SpaceHolder extends Displayable { 7 | public SpaceHolder(float relativeW, float relativeH) { 8 | super(relativeW, relativeH); 9 | init(); 10 | } 11 | 12 | public SpaceHolder() { 13 | super(); 14 | init(); 15 | } 16 | 17 | public SpaceHolder(float x, float y, float w, float h) { 18 | super(x, y, w, h); 19 | init(); 20 | } 21 | 22 | private void init() { 23 | setVisible(false); 24 | } 25 | 26 | @Override 27 | public void display() { 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/jui/customization/random: -------------------------------------------------------------------------------- 1 | color_mode: RGB 2 | 3 | container_margin_x: 5 4 | container_margin_y: 3 5 | container_spacing: 4 6 | 7 | container_visible: false 8 | display_contour: true 9 | rounded: false 10 | 11 | contour_thickness: 1 12 | rounding: 4 13 | font_scalar: 1.5f 14 | 15 | background_color: 46,215,70,76 16 | mouse_pressed_background_color: 24,223,174,180 17 | mouse_over_background_color: 232,100,200,220 18 | 19 | contour_color: 155,210,113,255 20 | mouse_pressed_contour_color: 34,67,103,255 21 | mouse_over_contour_color: 102,24,15,147 22 | 23 | text_color: 0,0,0,255 24 | mouse_pressed_text_color: 25,110,56,255 25 | mouse_over_text_color: 125,70,90,147 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/tests/specific/RawValueTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.core.components.RawValue; 4 | 5 | import static tests.TestPrint.l; 6 | 7 | /** 8 | * Created by Jiachen on 3/7/18. 9 | * RawValue Test 10 | */ 11 | public class RawValueTest { 12 | public static void main(String args[]) { 13 | l(RawValue.ZERO, RawValue.ONE, RawValue.UNDEF); 14 | l(new RawValue(Double.NEGATIVE_INFINITY).isInfinite()); 15 | l(RawValue.ZERO.isInteger()); 16 | l(-RawValue.INFINITY.doubleValue() < 0); 17 | l(RawValue.TWO.negate()); 18 | l(RawValue.INFINITY.longValue()); 19 | l(new RawValue(1231231234323.0).isInteger()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/tests/files/nodes/irr_num.txt: -------------------------------------------------------------------------------- 1 | (2/3)^(0-1/3) -> 9 2 | 3^(0-1/3) -> 7 3 | (3/2)^(0-2/3) -> 9 4 | 7/8*2 -> 5 5 | 2/5+3/7 -> 7 6 | 2*5/7 -> 5 7 | 3/4*(5/7) -> 7 8 | 3.5/4.7^2 -> 5 9 | 10^2.5 -> 3 10 | 3/4*5/6*(0-7)+(0-8)/9 -> 17 11 | 1/2*(1/2)^2 -> 9 12 | (2/3)^2 -> 5 13 | (2/3)^(4/3) -> 7 14 | (4/9)^(2/3) -> 7 15 | 3*3^(1/3) -> 7 16 | 3*3^(4/3) -> 7 17 | 8/3-2 -> 5 18 | 12^(1/3) -> 5 19 | 4^(1/3) -> 5 20 | 3*3^(1/3)*3 -> 9 21 | 3^(0-3) -> 5 22 | 3*4/12 -> 5 23 | 125^(1/2) -> 5 24 | -------------------------------------------------------------------------------- /src/tests/files/complexity/irr_num.txt: -------------------------------------------------------------------------------- 1 | 3^(0-3) -> 5 2 | (2/3)^(0-1/3) -> 9 3 | 3^(0-1/3) -> 7 4 | (3/2)^(0-2/3) -> 9 5 | 7/8*2 -> 5 6 | 2/5+3/7 -> 7 7 | 2*5/7 -> 5 8 | 3/4*(5/7) -> 7 9 | 3.5/4.7^2 -> 5 10 | 10^2.5 -> 3 11 | 3/4*5/6*(0-7)+(0-8)/9 -> 17 12 | 1/2*(1/2)^2 -> 9 13 | (2/3)^2 -> 5 14 | (2/3)^(4/3) -> 7 15 | (4/9)^(2/3) -> 7 16 | 3*3^(1/3) -> 7 17 | 3*3^(4/3) -> 7 18 | 8/3-2 -> 5 19 | 12^(1/3) -> 5 20 | 4^(1/3) -> 5 21 | 3*3^(1/3)*3 -> 9 22 | 3*4/12 -> 5 23 | 125^(1/2) -> 5 24 | -------------------------------------------------------------------------------- /src/jui/customization/default: -------------------------------------------------------------------------------- 1 | color_mode: RGB 2 | 3 | container_margin_x: 3 4 | container_margin_y: 3 5 | container_spacing: 3 6 | 7 | container_visible: false 8 | display_contour: true 9 | rounded: false 10 | 11 | contour_thickness: 0.1f 12 | rounding: 3 13 | 14 | background_color: 255,255,255,50 15 | mouse_pressed_background_color: 255,255,255,75 16 | mouse_over_background_color: 255,255,255,100 17 | 18 | contour_color: 0,0,0,255 19 | mouse_pressed_contour_color: 0,0,0,255 20 | mouse_over_contour_color: 0,0,0,255 21 | 22 | text_color: 255,255,255,255 23 | mouse_pressed_text_color: 255,255,255,255 24 | mouse_over_text_color: 255,255,255,255 25 | 26 | contextual_init_text_percentage: 0.55f 27 | auto_text_descent_compensation: false 28 | 29 | progress_bar_background_color: 255,255,255,200 30 | 31 | -------------------------------------------------------------------------------- /src/jas/utils/AnsiColor.java: -------------------------------------------------------------------------------- 1 | package jas.utils; 2 | 3 | /** 4 | * Created by Jiachen on 3/2/18. 5 | * An enum encapsulating Ansi color codes. 6 | */ 7 | public enum AnsiColor { 8 | BLACK("[0;30m"), 9 | BLUE("[0;34m"), 10 | GREEN("[0;32m"), 11 | CYAN("[0;36m"), 12 | RED("[0;31m"), 13 | PURPLE("[0;35m"), 14 | BROWN("[0;33m"), 15 | GRAY("[0;37m"), 16 | DARK_GRAY("[1;30m"), 17 | LIGHT_BLUE("[1;34m"), 18 | LIGHT_GREEN("[1;32m"), 19 | LIGHT_CYAN("[1;36m"), 20 | LIGHT_RED("[1;31m"), 21 | LIGHT_PURPLE("[1;35m"), 22 | YELLOW("[1;33m"), 23 | BOLD_BLACK("[1m"), 24 | WHITE("[1;37m"); 25 | private String raw; 26 | 27 | AnsiColor(String raw) { 28 | this.raw = raw; 29 | } 30 | 31 | public String toString() { 32 | return this.raw; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/tests/files/irr_num.txt: -------------------------------------------------------------------------------- 1 | 3^(0-3) -> (1/27) 2 | (2/3)^(0-1/3) -> (1/2)*3^(1/3)*2^(2/3) 3 | 3^(0-1/3) -> (1/3)*3^(2/3) 4 | (3/2)^(0-2/3) -> 2^(2/3)*3^(1/3)*(1/3) 5 | 7/8*2 -> (7/4) 6 | 2/5+3/7 -> (29/35) 7 | 2*5/7 -> (10/7) 8 | 3/4*(5/7) -> (15/28) 9 | 3.5/4.7^2 -> (350/2209) 10 | 10^2.5 -> 100*10^(1/2) 11 | 3/4*5/6*(0-7)+(0-8)/9 -> (-379/72) 12 | 1/2*(1/2)^2 -> (1/8) 13 | (2/3)^2 -> (4/9) 14 | (2/3)^(4/3) -> (2/9)*2^(1/3)*3^(2/3) 15 | (4/9)^(2/3) -> (2/9)*2^(1/3)*3^(2/3) 16 | 3*3^(1/3) -> 3*3^(1/3) 17 | 3*3^(4/3) -> 3^(1/3)*9 18 | 8/3-2 -> (2/3) 19 | 12^(1/3) -> 3^(1/3)*2^(2/3) 20 | 4^(1/3) -> 2^(2/3) 21 | 3*3^(1/3)*3 -> 3^(1/3)*9 22 | 3*4/12 -> 1 23 | 125^(1/2) -------------------------------------------------------------------------------- /src/tests/files/beautify/irr_num.txt: -------------------------------------------------------------------------------- 1 | 3^(0-3) -> (1/27) 2 | (2/3)^(0-1/3) -> 3^(1/3)*2^(2/3)/2 3 | 3^(0-1/3) -> 3^(2/3)/3 4 | (3/2)^(0-2/3) -> 2^(2/3)*3^(1/3)/3 5 | 7/8*2 -> (7/4) 6 | 2/5+3/7 -> (29/35) 7 | 2*5/7 -> (10/7) 8 | 3/4*(5/7) -> (15/28) 9 | 3.5/4.7^2 -> (350/2209) 10 | 10^2.5 -> 100*10^(1/2) 11 | 3/4*5/6*(0-7)+(0-8)/9 -> (-379/72) 12 | 1/2*(1/2)^2 -> (1/8) 13 | (2/3)^2 -> (4/9) 14 | (2/3)^(4/3) -> 2*2^(1/3)*3^(2/3)/9 15 | (4/9)^(2/3) -> 2*2^(1/3)*3^(2/3)/9 16 | 3*3^(1/3) -> 3*3^(1/3) 17 | 3*3^(4/3) -> 9*3^(1/3) 18 | 8/3-2 -> (2/3) 19 | 12^(1/3) -> 3^(1/3)*2^(2/3) 20 | 4^(1/3) -> 2^(2/3) 21 | 3*3^(1/3)*3 -> 9*3^(1/3) 22 | 3*4/12 -> 1 23 | 125^(1/2) -> 5*5^(1/2) 24 | -------------------------------------------------------------------------------- /src/tests/files/simplest/irr_num.txt: -------------------------------------------------------------------------------- 1 | (2/3)^(0-1/3) -> (1/2)*2^(2/3)*3^(1/3) 2 | 3^(0-1/3) -> (1/3)*3^(2/3) 3 | (3/2)^(0-2/3) -> (1/3)*2^(2/3)*3^(1/3) 4 | 7/8*2 -> (7/4) 5 | 2/5+3/7 -> (29/35) 6 | 2*5/7 -> (10/7) 7 | 3/4*(5/7) -> (15/28) 8 | 3.5/4.7^2 -> (350/2209) 9 | 10^2.5 -> 100*10^(1/2) 10 | 3/4*5/6*(0-7)+(0-8)/9 -> (-379/72) 11 | 1/2*(1/2)^2 -> (1/8) 12 | (2/3)^2 -> (4/9) 13 | (2/3)^(4/3) -> (2/9)*2^(1/3)*3^(2/3) 14 | (4/9)^(2/3) -> (2/9)*2^(1/3)*3^(2/3) 15 | 3*3^(1/3) -> 3*3^(1/3) 16 | 3*3^(4/3) -> 3^(1/3)*9 17 | 8/3-2 -> (2/3) 18 | 12^(1/3) -> 2^(2/3)*3^(1/3) 19 | 4^(1/3) -> 2^(2/3) 20 | 3*3^(1/3)*3 -> 3^(1/3)*9 21 | 3^(0-3) -> (1/27) 22 | 3*4/12 -> 1 23 | 125^(1/2) -> 5*5^(1/2) 24 | -------------------------------------------------------------------------------- /src/tests/files/additional/irr_num.txt: -------------------------------------------------------------------------------- 1 | (2/3)^(0-1/3) -> (2/3)^(0+((-1/3))) 2 | 3^(0-1/3) -> 3^(0+((-1/3))) 3 | (3/2)^(0-2/3) -> (3/2)^(0+((-2/3))) 4 | 7/8*2 -> 7/8*2 5 | 2/5+3/7 -> 2/5+3/7 6 | 2*5/7 -> 2*5/7 7 | 3/4*(5/7) -> 3/4*(5/7) 8 | 3.5/4.7^2 -> 3.5/4.7^2 9 | 10^2.5 -> 10^2.5 10 | 3/4*5/6*(0-7)+(0-8)/9 -> 3/4*5/6*(0+(-7))+(0+(-8))/9 11 | 1/2*(1/2)^2 -> 1/2*(1/2)^2 12 | (2/3)^2 -> (2/3)^2 13 | (2/3)^(4/3) -> (2/3)^(4/3) 14 | (4/9)^(2/3) -> (4/9)^(2/3) 15 | 3*3^(1/3) -> 3*3^(1/3) 16 | 3*3^(4/3) -> 3*3^(4/3) 17 | 8/3-2 -> 8/3+(-2) 18 | 12^(1/3) -> 12^(1/3) 19 | 4^(1/3) -> 4^(1/3) 20 | 3*3^(1/3)*3 -> 3*3^(1/3)*3 21 | 3^(0-3) -> 3^(0+(-3)) 22 | 3*4/12 -> 3*4/12 23 | 125^(1/2) -> 125^(1/2) 24 | -------------------------------------------------------------------------------- /src/tests/files/expansion/irr_num.txt: -------------------------------------------------------------------------------- 1 | 3^(0-3) -> (1/27) 2 | (2/3)^(0-1/3) -> (1/2)*3^(1/3)*2^(2/3) 3 | 3^(0-1/3) -> (1/3)*3^(2/3) 4 | (3/2)^(0-2/3) -> 2^(2/3)*3^(1/3)*(1/3) 5 | 7/8*2 -> (7/4) 6 | 2/5+3/7 -> (29/35) 7 | 2*5/7 -> (10/7) 8 | 3/4*(5/7) -> (15/28) 9 | 3.5/4.7^2 -> (350/2209) 10 | 10^2.5 -> 100*10^(1/2) 11 | 3/4*5/6*(0-7)+(0-8)/9 -> (-379/72) 12 | 1/2*(1/2)^2 -> (1/8) 13 | (2/3)^2 -> (4/9) 14 | (2/3)^(4/3) -> (2/9)*2^(1/3)*3^(2/3) 15 | (4/9)^(2/3) -> (2/9)*2^(1/3)*3^(2/3) 16 | 3*3^(1/3) -> 3*3^(1/3) 17 | 3*3^(4/3) -> 3^(1/3)*9 18 | 8/3-2 -> (2/3) 19 | 12^(1/3) -> 3^(1/3)*2^(2/3) 20 | 4^(1/3) -> 2^(2/3) 21 | 3*3^(1/3)*3 -> 3^(1/3)*9 22 | 3*4/12 -> 1 23 | 125^(1/2) -> 5*5^(1/2) 24 | -------------------------------------------------------------------------------- /src/tests/files/simplification/irr_num.txt: -------------------------------------------------------------------------------- 1 | 3^(0-3) -> (1/27) 2 | (2/3)^(0-1/3) -> (1/2)*3^(1/3)*2^(2/3) 3 | 3^(0-1/3) -> (1/3)*3^(2/3) 4 | (3/2)^(0-2/3) -> 2^(2/3)*3^(1/3)*(1/3) 5 | 7/8*2 -> (7/4) 6 | 2/5+3/7 -> (29/35) 7 | 2*5/7 -> (10/7) 8 | 3/4*(5/7) -> (15/28) 9 | 3.5/4.7^2 -> (350/2209) 10 | 10^2.5 -> 100*10^(1/2) 11 | 3/4*5/6*(0-7)+(0-8)/9 -> (-379/72) 12 | 1/2*(1/2)^2 -> (1/8) 13 | (2/3)^2 -> (4/9) 14 | (2/3)^(4/3) -> (2/9)*2^(1/3)*3^(2/3) 15 | (4/9)^(2/3) -> (2/9)*2^(1/3)*3^(2/3) 16 | 3*3^(1/3) -> 3*3^(1/3) 17 | 3*3^(4/3) -> 3^(1/3)*9 18 | 8/3-2 -> (2/3) 19 | 12^(1/3) -> 3^(1/3)*2^(2/3) 20 | 4^(1/3) -> 2^(2/3) 21 | 3*3^(1/3)*3 -> 3^(1/3)*9 22 | 3*4/12 -> 1 23 | 125^(1/2) -> 5*5^(1/2) 24 | -------------------------------------------------------------------------------- /src/tests/files/exponential/irr_num.txt: -------------------------------------------------------------------------------- 1 | (2/3)^(0-1/3) -> (2*(1/3))^(0-1*(1/3)) 2 | 3^(0-1/3) -> 3^(0-1*(1/3)) 3 | (3/2)^(0-2/3) -> (3*(1/2))^(0-2*(1/3)) 4 | 7/8*2 -> 7*(1/8)*2 5 | 2/5+3/7 -> 2*(1/5)+3*(1/7) 6 | 2*5/7 -> 2*5*(1/7) 7 | 3/4*(5/7) -> 3*(1/4)*(5*(1/7)) 8 | 3.5/4.7^2 -> 3.5*(100/2209) 9 | 10^2.5 -> 10^2.5 10 | 3/4*5/6*(0-7)+(0-8)/9 -> 3*(1/4)*5*(1/6)*(0-7)+(0-8)*(1/9) 11 | 1/2*(1/2)^2 -> 1*(1/2)*(1*(1/2))^2 12 | (2/3)^2 -> (2*(1/3))^2 13 | (2/3)^(4/3) -> (2*(1/3))^(4*(1/3)) 14 | (4/9)^(2/3) -> (4*(1/9))^(2*(1/3)) 15 | 3*3^(1/3) -> 3*3^(1*(1/3)) 16 | 3*3^(4/3) -> 3*3^(4*(1/3)) 17 | 8/3-2 -> 8*(1/3)-2 18 | 12^(1/3) -> 12^(1*(1/3)) 19 | 4^(1/3) -> 4^(1*(1/3)) 20 | 3*3^(1/3)*3 -> 3*3^(1*(1/3))*3 21 | 3^(0-3) -> 3^(0-3) 22 | 3*4/12 -> 3*4*(1/12) 23 | 125^(1/2) -> 125^(1*(1/2)) 24 | -------------------------------------------------------------------------------- /src/CasCmdline.java: -------------------------------------------------------------------------------- 1 | import jas.core.Compiler; 2 | import jas.core.JASException; 3 | 4 | import java.util.Scanner; 5 | 6 | import static jas.utils.ColorFormatter.*; 7 | import static tests.TestPrint.l; 8 | import static tests.TestPrint.p; 9 | 10 | /** 11 | * Created by Jiachen on 3/2/18. 12 | * JMC Computer Algebra System commandline application 13 | */ 14 | public class CasCmdline { 15 | public static void main(String args[]) { 16 | System.out.println("Welcome to Java Algebra System (JAS)\nDesigned by Jiachen Ren\nMIT licensed (c) 2018\n"); 17 | Scanner scanner = new Scanner(System.in); 18 | while (true) { 19 | p(boldBlack("\t: ")); 20 | String input = scanner.nextLine(); 21 | if (input.equals("exit")) return; 22 | try { 23 | l(boldBlack("\t= ") + Compiler.compile(input).simplify().coloredString() + "\n"); 24 | } catch (JASException e) { 25 | l(lightBlue("\t> ") + lightRed(e.getMessage()) + "\n"); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/tests/files/nodes/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2*x) -> 8 2 | atan(tan(x)) -> 3 3 | asin(sin(x)) -> 3 4 | acos(cos(2*ln(x))) -> 6 5 | atan(tan(5*pi/2)) -> 7 6 | tan(0-3*pi/2) -> 8 7 | sec(0-3*pi/2) -> 8 8 | cot(pi) -> 2 9 | cot(0) -> 2 10 | csc(0) -> 2 11 | csc(100*pi) -> 4 12 | csc(pi/2) -> 4 13 | log(10) -> 2 14 | log(100) -> 2 15 | ln(225) -> 2 16 | ln(e) -> 2 17 | int(3.5) -> 2 18 | ln(e^3) -> 4 19 | ln(e^3+x) -> 6 20 | ln(e^3*x) -> 6 21 | ln(x) -> 2 22 | ln(e^(3*x)) -> 6 23 | cos(pi) -> 2 24 | sin(pi) -> 2 25 | tan(pi) -> 2 26 | 100^log(5) -> 4 27 | 1000^log(5) -> 4 28 | (e^3)^ln(3) -> 6 29 | e^ln(5) -> 4 30 | ln((2/3)^(3/2)) -> 8 31 | ln(2^(3/2)) -> 6 32 | log(13) -> 2 33 | tan(3*pi/2) -> 6 34 | ln(37) -> 2 35 | ln(1/4) -> 4 36 | ln(0-1) -> 4 37 | ln(0-1*x) -> 6 38 | -------------------------------------------------------------------------------- /src/tests/files/complexity/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2) -> 7 2 | tan(3*pi/2*x) -> 11 3 | atan(tan(x)) -> 5 4 | asin(sin(x)) -> 5 5 | acos(cos(2*ln(x))) -> 8 6 | atan(tan(5*pi/2)) -> 8 7 | tan(0-3*pi/2) -> 9 8 | sec(0-3*pi/2) -> 9 9 | cot(pi) -> 3 10 | cot(0) -> 2 11 | csc(0) -> 2 12 | csc(100*pi) -> 5 13 | csc(pi/2) -> 5 14 | log(10) -> 2 15 | log(100) -> 2 16 | ln(225) -> 2 17 | ln(e) -> 3 18 | int(3.5) -> 2 19 | ln(e^3) -> 5 20 | ln(e^3+x) -> 9 21 | ln(e^3*x) -> 9 22 | ln(x) -> 4 23 | ln(e^(3*x)) -> 9 24 | cos(pi) -> 3 25 | sin(pi) -> 3 26 | tan(pi) -> 3 27 | 100^log(5) -> 4 28 | 1000^log(5) -> 4 29 | (e^3)^ln(3) -> 7 30 | e^ln(5) -> 5 31 | ln((2/3)^(3/2)) -> 8 32 | ln(2^(3/2)) -> 6 33 | log(13) -> 2 34 | ln(37) -> 2 35 | ln(1/4) -> 4 36 | ln(0-1) -> 4 37 | ln(0-1*x) -> 8 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jiachen Ren 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/jas/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package jas.utils; 2 | 3 | import java.io.*; 4 | import java.net.URI; 5 | import java.net.URISyntaxException; 6 | 7 | /** 8 | * Created by Jiachen on 3/10/18. 9 | * Utils 10 | */ 11 | public class Utils { 12 | public static String read(String filePath) { 13 | final String[] acc = {""}; 14 | InputStream inputStream; 15 | inputStream = Utils.class.getResourceAsStream(filePath); 16 | InputStreamReader reader = new InputStreamReader(inputStream); 17 | BufferedReader bufferedReader = new BufferedReader(reader); 18 | bufferedReader.lines().forEach(line -> acc[0] += line + "\n"); 19 | return acc[0]; 20 | } 21 | 22 | public static void write(String filePath, String content) { 23 | try { 24 | URI uri = Class.class.getResource(filePath).toURI(); 25 | PrintWriter pw = new PrintWriter(new File(uri)); 26 | pw.write(content); 27 | pw.flush(); 28 | pw.close(); 29 | } catch (IOException | URISyntaxException e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/tests/specific/MathContextTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.MathContext; 4 | import jas.core.Node; 5 | import jas.core.components.RawValue; 6 | 7 | import java.math.BigInteger; 8 | import java.util.ArrayList; 9 | 10 | import static jas.utils.ColorFormatter.*; 11 | import static tests.TestPrint.l; 12 | 13 | public class MathContextTest { 14 | 15 | public static void main(String[] args) { 16 | ArrayList factors = MathContext.factor(new BigInteger("100000")); 17 | for (BigInteger b : factors) 18 | System.out.println(b); 19 | // l(MathContext.factorial(new BigInteger("300"))); 20 | for (int i = 0; i < 10000; i++) { 21 | int finalI = i; 22 | MathContext.toBaseExponentPairs(new BigInteger(Integer.toString(i))).stream() 23 | .map(pair -> new RawValue(pair[0]).exp(pair[1])) 24 | .reduce(Node::mult) 25 | .ifPresent(o -> l(boldBlack(finalI + " -> ") 26 | + lightBlue(o + " -> ") 27 | + lightGreen(o.val()))); 28 | } 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/jas/core/Mode.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | import static jas.utils.AnsiColor.*; 4 | 5 | /** 6 | * Created by Jiachen on 3/4/18. 7 | * Mode: radians vs. degrees, debug on/off, etc. 8 | */ 9 | public class Mode { 10 | public static boolean DEBUG = false; 11 | public static boolean FRACTION = true; 12 | public static boolean COMPACT = true; 13 | public static String U_OP_COLOR = LIGHT_BLUE.toString(); 14 | public static String BIN_OP_COLOR = "[0m"; 15 | public static String CUSTOM_OP_COLOR = LIGHT_PURPLE.toString(); 16 | public static String CONSTANT_COLOR = LIGHT_CYAN.toString(); 17 | public static String CURLY_BRACKET_COLOR = LIGHT_PURPLE.toString(); 18 | public static String COMMA_COLOR = LIGHT_PURPLE.toString(); 19 | public static String PARENTHESIS_COLOR = LIGHT_RED.toString(); 20 | public static String LITERAL_COLOR = LIGHT_GREEN.toString(); 21 | public static String NUMBER_COLOR = GREEN.toString(); 22 | public static String FRACTION_COLOR = GREEN.toString(); 23 | public static String VARIABLE_COLOR = BOLD_BLACK.toString(); 24 | public static String DECIMAL_FORMAT = "0.##################"; //needs improvement! 25 | } 26 | -------------------------------------------------------------------------------- /src/tests/files/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2) -> undef 2 | tan(3*pi/2*x) -> tan(pi*(3/2)*x) 3 | atan(tan(x)) -> atan(tan(x)) 4 | asin(sin(x)) -> asin(sin(x)) 5 | acos(cos(2*ln(x))) -> acos(cos(2*ln(x))) 6 | atan(tan(5*pi/2)) -> undef 7 | tan(0-3*pi/2) -> undef 8 | sec(0-3*pi/2) -> undef 9 | cot(pi) -> undef 10 | cot(0) -> undef 11 | csc(0) -> undef 12 | csc(100*pi) -> undef 13 | csc(pi/2) -> 1 14 | log(10) -> 1 15 | log(100) -> 2 16 | ln(225) -> 2*ln(15) 17 | ln(e) -> 1 18 | int(3.5) -> 3 19 | ln(e^3) -> 3 20 | ln(e^3+x) -> ln(e^3+x) 21 | ln(e^3*x) -> ln(e^3*x) 22 | ln(x) -> ln(x) 23 | ln(e^(3*x)) -> (3*x) 24 | cos(pi) -> -1 25 | sin(pi) -> 0 26 | tan(pi) -> 0 27 | 100^log(5) -> 25 28 | 1000^log(5) -> 125 29 | (e^3)^ln(3) -> 27 30 | e^ln(5) -> 5 31 | ln((2/3)^(3/2)) -> ln((2/9)*2^(1/2)*3^(1/2)) 32 | ln(2^(3/2)) -> ln(2*2^(1/2)) 33 | log(13) -> log(13) 34 | ln(37) -> ln(37) 35 | ln(1/4) -> ln((1/4)) 36 | ln(-1) 37 | ln(-1*x) 38 | -------------------------------------------------------------------------------- /src/tests/specific/GraphTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.core.Compiler; 4 | import jas.graph.GraphFunction; 5 | import jas.graph.Graph; 6 | import jui.JNode; 7 | import processing.core.PApplet; 8 | 9 | /** 10 | * Created by Jiachen on 21/05/2017. 11 | * Graph UI Test 12 | */ 13 | public class GraphTest extends PApplet { 14 | public static void main(String args[]) { 15 | String sketch = Thread.currentThread().getStackTrace()[1].getClassName(); 16 | Thread main = new Thread(() -> PApplet.main(sketch)); 17 | main.start(); 18 | } 19 | 20 | public void settings() { 21 | size(800, 600, FX2D); 22 | } 23 | 24 | public void setup() { 25 | JNode.init(this); 26 | JNode.add(new Graph(0, 0, width, height)); 27 | Graph graph = ((Graph) JNode.getDisplayables().get(0)); 28 | graph.add(new GraphFunction(Compiler.compile("x"))); 29 | 30 | } 31 | 32 | public void draw() { 33 | background(255, 255, 255); 34 | JNode.run(); 35 | } 36 | 37 | public void keyPressed() { 38 | JNode.keyPressed(); 39 | } 40 | 41 | public void keyReleased() { 42 | JNode.keyReleased(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/tests/cas/Benchmark.java: -------------------------------------------------------------------------------- 1 | package tests.cas; 2 | 3 | import jas.core.Compiler; 4 | import jas.core.Node; 5 | import jas.utils.Timer; 6 | import tests.AutoTest; 7 | import tests.TestPrint; 8 | 9 | import static tests.TestPrint.l; 10 | 11 | /** 12 | * Created by Jiachen on 3/24/18. 13 | * Benchmark 14 | */ 15 | public class Benchmark { 16 | public static void main(String args[]) throws Exception { 17 | l("Running..."); 18 | Timer timer = new Timer(); 19 | AutoTest.WRITE = false; 20 | // Mode.COMPACT = false; 21 | Node node = Compiler.compile("derivative(x*cos(x)*sin(x)*ln(x),x,5)"); 22 | for (int i = 0; i < 5; i++) { 23 | TestPrint.DISABLED = true; 24 | AutoTest.main(args); 25 | l(node.copy().simplify().coloredString()); 26 | l(Compiler.compile("(a+c+b-d+f+e+g+i+h+j)*(a+e+c+f+h+j+b-d+g+i)").simplify().coloredString()); 27 | l(Compiler.compile("(a+c+b+d+f+e+g+i+h+j)*(a+e+c+f+h+j+b+d+g+i)").expand().simplify().coloredString()); 28 | l(Compiler.compile("derivative(ln(x)*x*cos(x),x,10)").simplify().eval(6)); 29 | TestPrint.DISABLED = false; 30 | } 31 | l("Done... finished within " + timer); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/tests/files/beautify/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2) -> undef 2 | tan(3*pi/2*x) -> tan(3*pi*x/2) 3 | atan(tan(x)) -> atan(tan(x)) 4 | asin(sin(x)) -> asin(sin(x)) 5 | acos(cos(2*ln(x))) -> acos(cos(2*ln(x))) 6 | atan(tan(5*pi/2)) -> undef 7 | tan(0-3*pi/2) -> undef 8 | sec(0-3*pi/2) -> undef 9 | cot(pi) -> undef 10 | cot(0) -> undef 11 | csc(0) -> undef 12 | csc(100*pi) -> undef 13 | csc(pi/2) -> 1 14 | log(10) -> 1 15 | log(100) -> 2 16 | ln(225) -> 2*ln(15) 17 | ln(e) -> 1 18 | int(3.5) -> 3 19 | ln(e^3) -> 3 20 | ln(e^3+x) -> ln(e^3+x) 21 | ln(e^3*x) -> ln(e^3*x) 22 | ln(x) -> ln(x) 23 | ln(e^(3*x)) -> 3*x 24 | cos(pi) -> -1 25 | sin(pi) -> 0 26 | tan(pi) -> 0 27 | 100^log(5) -> 25 28 | 1000^log(5) -> 125 29 | (e^3)^ln(3) -> 27 30 | e^ln(5) -> 5 31 | ln((2/3)^(3/2)) -> ln(2*2^(1/2)*3^(1/2)/9) 32 | ln(2^(3/2)) -> ln(2*2^(1/2)) 33 | log(13) -> log(13) 34 | ln(37) -> ln(37) 35 | ln(1/4) -> ln((1/4)) 36 | ln(0-1) -> undef 37 | ln(0-1*x) -> ln((-1)*x) 38 | -------------------------------------------------------------------------------- /src/tests/files/expansion/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2) -> undef 2 | tan(3*pi/2*x) -> tan(pi*x*(3/2)) 3 | atan(tan(x)) -> atan(tan(x)) 4 | asin(sin(x)) -> asin(sin(x)) 5 | acos(cos(2*ln(x))) -> acos(cos(2*ln(x))) 6 | atan(tan(5*pi/2)) -> undef 7 | tan(0-3*pi/2) -> undef 8 | sec(0-3*pi/2) -> undef 9 | cot(pi) -> undef 10 | cot(0) -> undef 11 | csc(0) -> undef 12 | csc(100*pi) -> undef 13 | csc(pi/2) -> 1 14 | log(10) -> 1 15 | log(100) -> 2 16 | ln(225) -> 2*ln(15) 17 | ln(e) -> 1 18 | int(3.5) -> 3 19 | ln(e^3) -> 3 20 | ln(e^3+x) -> ln(e^3+x) 21 | ln(e^3*x) -> ln(e^3*x) 22 | ln(x) -> ln(x) 23 | ln(e^(3*x)) -> (3*x) 24 | cos(pi) -> -1 25 | sin(pi) -> 0 26 | tan(pi) -> 0 27 | 100^log(5) -> 25 28 | 1000^log(5) -> 125 29 | (e^3)^ln(3) -> 27 30 | e^ln(5) -> 5 31 | ln((2/3)^(3/2)) -> ln((2/9)*2^(1/2)*3^(1/2)) 32 | ln(2^(3/2)) -> ln(2*2^(1/2)) 33 | log(13) -> log(13) 34 | ln(37) -> ln(37) 35 | ln(1/4) -> ln((1/4)) 36 | ln(0-1) -> undef 37 | ln(0-1*x) -> ln(x*(-1)) 38 | -------------------------------------------------------------------------------- /src/tests/files/simplest/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2*x) -> tan((3/2)*pi*x) 2 | atan(tan(x)) -> atan(tan(x)) 3 | asin(sin(x)) -> asin(sin(x)) 4 | acos(cos(2*ln(x))) -> acos(cos(2*ln(x))) 5 | atan(tan(5*pi/2)) -> undef 6 | tan(0-3*pi/2) -> undef 7 | sec(0-3*pi/2) -> undef 8 | cot(pi) -> undef 9 | cot(0) -> undef 10 | csc(0) -> undef 11 | csc(100*pi) -> undef 12 | csc(pi/2) -> 1 13 | log(10) -> 1 14 | log(100) -> 2 15 | ln(225) -> 2*ln(15) 16 | ln(e) -> 1 17 | int(3.5) -> 3 18 | ln(e^3) -> 3 19 | ln(e^3+x) -> ln(e^3+x) 20 | ln(e^3*x) -> ln(e^3*x) 21 | ln(x) -> ln(x) 22 | ln(e^(3*x)) -> 3*x 23 | cos(pi) -> -1 24 | sin(pi) -> 0 25 | tan(pi) -> 0 26 | 100^log(5) -> 25 27 | 1000^log(5) -> 125 28 | (e^3)^ln(3) -> 27 29 | e^ln(5) -> 5 30 | ln((2/3)^(3/2)) -> ln((2/9)*2^(1/2)*3^(1/2)) 31 | ln(2^(3/2)) -> ln(2*2^(1/2)) 32 | log(13) -> log(13) 33 | tan(3*pi/2) -> undef 34 | ln(37) -> ln(37) 35 | ln(1/4) -> ln((1/4)) 36 | ln(0-1) -> undef 37 | ln(0-1*x) -> ln((-1)*x) 38 | -------------------------------------------------------------------------------- /src/jas/core/LeafNode.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | /** 4 | * Created by Jiachen on 3/10/18. 5 | * Leaf Node: super class of Variable and RawValue 6 | */ 7 | public abstract class LeafNode extends Node implements BinLeafNode { 8 | public abstract Node copy(); 9 | 10 | public int levelOf(Node o) { 11 | return this.equals(o) ? 0 : -1; 12 | } 13 | 14 | public abstract String toString(); 15 | 16 | public int numNodes() { 17 | return 1; 18 | } 19 | 20 | // public abstract Node firstDerivative(); 21 | 22 | public abstract int complexity(); 23 | 24 | public Node beautify() { 25 | return this; 26 | } 27 | 28 | public abstract Node explicitNegativeForm(); 29 | 30 | public Node toAdditionOnly() { 31 | return this; 32 | } 33 | 34 | public Node toExponentialForm() { 35 | return this; 36 | } 37 | 38 | public Node expand() { 39 | return this; 40 | } 41 | 42 | public Node replace(Node o, Node r) { 43 | return this.equals(o) ? r : this; 44 | } 45 | 46 | public abstract boolean isUndefined(); 47 | 48 | /** 49 | * LeafNode, nothing could be done for reordering. 50 | */ 51 | public void order() { 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/tests/files/simplification/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2) -> undef 2 | tan(3*pi/2*x) -> tan(pi*(3/2)*x) 3 | atan(tan(x)) -> atan(tan(x)) 4 | asin(sin(x)) -> asin(sin(x)) 5 | acos(cos(2*ln(x))) -> acos(cos(2*ln(x))) 6 | atan(tan(5*pi/2)) -> undef 7 | tan(0-3*pi/2) -> undef 8 | sec(0-3*pi/2) -> undef 9 | cot(pi) -> undef 10 | cot(0) -> undef 11 | csc(0) -> undef 12 | csc(100*pi) -> undef 13 | csc(pi/2) -> 1 14 | log(10) -> 1 15 | log(100) -> 2 16 | ln(225) -> 2*ln(15) 17 | ln(e) -> 1 18 | int(3.5) -> 3 19 | ln(e^3) -> 3 20 | ln(e^3+x) -> ln(e^3+x) 21 | ln(e^3*x) -> ln(e^3*x) 22 | ln(x) -> ln(x) 23 | ln(e^(3*x)) -> (3*x) 24 | cos(pi) -> -1 25 | sin(pi) -> 0 26 | tan(pi) -> 0 27 | 100^log(5) -> 25 28 | 1000^log(5) -> 125 29 | (e^3)^ln(3) -> 27 30 | e^ln(5) -> 5 31 | ln((2/3)^(3/2)) -> ln((2/9)*2^(1/2)*3^(1/2)) 32 | ln(2^(3/2)) -> ln(2*2^(1/2)) 33 | log(13) -> log(13) 34 | ln(37) -> ln(37) 35 | ln(1/4) -> ln((1/4)) 36 | ln(0-1) -> undef 37 | ln(0-1*x) -> ln((-1)*x) 38 | -------------------------------------------------------------------------------- /src/jas/graph/SuppliedVar.java: -------------------------------------------------------------------------------- 1 | package jas.graph; 2 | 3 | import jas.core.Mode; 4 | import jas.core.Node; 5 | import jas.core.components.Variable; 6 | 7 | /** 8 | * Created by Jiachen on 3/4/18. 9 | * Supplied Variable 10 | */ 11 | public class SuppliedVar extends Variable { 12 | private double val; 13 | 14 | public SuppliedVar(String name) { 15 | super(name); 16 | } 17 | 18 | @Override 19 | public double eval(double x) { 20 | return val; 21 | } 22 | 23 | @Override 24 | public boolean equals(Node other) { 25 | return other instanceof SuppliedVar && ((SuppliedVar) other).getName().equals(getName()); 26 | } 27 | 28 | public String toString() { 29 | return Mode.DEBUG ? "&" + getName() + "&" : getName(); 30 | } 31 | 32 | @Override 33 | public SuppliedVar copy() { 34 | super.copy(); 35 | return new SuppliedVar(this.getName()).setVal(this.val); 36 | } 37 | 38 | public SuppliedVar setVal(double val) { 39 | this.val = val; 40 | return this; 41 | } 42 | 43 | @Override 44 | public double val() { 45 | return val; 46 | } 47 | 48 | @Override 49 | public Node replace(Node o, Node r) { 50 | return o.equals(this) ? r : this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/jui/EventListener.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | /** 4 | * Created by Jiachen on 30/04/2017. 5 | */ 6 | public class EventListener { 7 | private Event event; 8 | private Runnable attachedMethod; 9 | private String id; 10 | private boolean disabled; 11 | 12 | public EventListener(String id, Event event) { 13 | this.event = event; 14 | this.id = id; 15 | disabled = false; 16 | } 17 | 18 | public Event getEvent() { 19 | return event; 20 | } 21 | 22 | public EventListener setEvent(Event event) { 23 | this.event = event; 24 | return this; 25 | } 26 | 27 | public void invoke() { 28 | if (attachedMethod != null && !disabled) 29 | attachedMethod.run(); 30 | } 31 | 32 | public EventListener attachMethod(Runnable runnable) { 33 | this.attachedMethod = runnable; 34 | return this; 35 | } 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String temp) { 42 | this.id = temp; 43 | } 44 | 45 | public EventListener setDisabled(boolean disabled) { 46 | this.disabled = disabled; 47 | return this; 48 | } 49 | 50 | public boolean isDisabled() { 51 | return disabled; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/jas/core/operations/Argument.java: -------------------------------------------------------------------------------- 1 | package jas.core.operations; 2 | 3 | import jas.core.JASException; 4 | import jas.core.Node; 5 | import jas.core.components.*; 6 | 7 | /** 8 | * Created by Jiachen on 3/17/18. 9 | * Argument type 10 | */ 11 | public enum Argument { 12 | NUMBER, 13 | VARIABLE, 14 | ANY, 15 | OPERATION, 16 | MATRIX, 17 | LIST, 18 | VECTOR, 19 | LITERAL; 20 | 21 | public static Argument resolve(Node o) { 22 | if (!o.isNaN() || o instanceof RawValue) { 23 | return NUMBER; 24 | } else if (o instanceof Literal) { // be careful, Literal is a subclass of Variable. 25 | return LITERAL; 26 | } else if (o instanceof Variable) { 27 | return VARIABLE; 28 | } else if (o instanceof Operation) { 29 | return OPERATION; 30 | } else if (o instanceof Matrix) { 31 | return MATRIX; 32 | } else if (o instanceof List) { 33 | return LIST; 34 | } else if (o instanceof Vector) { 35 | return VECTOR; 36 | } 37 | throw new JASException("cannot resolve argument type \"" + o + "\""); 38 | } 39 | 40 | public boolean equals(Argument other) { 41 | return super.equals(ANY) || other == ANY || super.equals(other); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/jas/core/operations/Manipulation.java: -------------------------------------------------------------------------------- 1 | package jas.core.operations; 2 | 3 | import jas.core.Nameable; 4 | import jas.core.Node; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * Created by Jiachen on 3/17/18. 10 | * Named Manipulation 11 | */ 12 | public class Manipulation implements Nameable, Manipulable { 13 | private String name; 14 | private Manipulable manipulable; 15 | private Signature signature; 16 | 17 | public Manipulation(String name, Signature signature, Manipulable manipulable) { 18 | this.manipulable = manipulable; 19 | this.signature = signature; 20 | this.name = name; 21 | } 22 | 23 | public Node manipulate(ArrayList operands) { 24 | return manipulable.manipulate(operands); 25 | } 26 | 27 | public Signature getSignature() { 28 | return signature; 29 | } 30 | 31 | public boolean equals(Manipulation other) { 32 | return other.getName().equals(getName()) && other.signature.equals(signature); 33 | } 34 | 35 | public boolean equals(String name, Signature signature) { 36 | return name.equals(getName()) && getSignature().equals(signature); 37 | } 38 | 39 | public String toString() { 40 | return getName() + "(" + signature.toString() + ")"; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/tests/files/additional/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2*x) -> tan(3*pi/2*x) 2 | atan(tan(x)) -> atan(tan(x)) 3 | asin(sin(x)) -> asin(sin(x)) 4 | acos(cos(2*ln(x))) -> acos(cos(2*ln(x))) 5 | atan(tan(5*pi/2)) -> atan(tan(5*pi/2)) 6 | tan(0-3*pi/2) -> tan(0+pi*((-3/2))) 7 | sec(0-3*pi/2) -> sec(0+pi*((-3/2))) 8 | cot(pi) -> cot(pi) 9 | cot(0) -> cot(0) 10 | csc(0) -> csc(0) 11 | csc(100*pi) -> csc(100*pi) 12 | csc(pi/2) -> csc(pi/2) 13 | log(10) -> log(10) 14 | log(100) -> log(100) 15 | ln(225) -> ln(225) 16 | ln(e) -> ln(e) 17 | int(3.5) -> int(3.5) 18 | ln(e^3) -> ln(e^3) 19 | ln(e^3+x) -> ln(e^3+x) 20 | ln(e^3*x) -> ln(e^3*x) 21 | ln(x) -> ln(x) 22 | ln(e^(3*x)) -> ln(e^(3*x)) 23 | cos(pi) -> cos(pi) 24 | sin(pi) -> sin(pi) 25 | tan(pi) -> tan(pi) 26 | 100^log(5) -> 100^log(5) 27 | 1000^log(5) -> 1000^log(5) 28 | (e^3)^ln(3) -> (e^3)^ln(3) 29 | e^ln(5) -> e^ln(5) 30 | ln((2/3)^(3/2)) -> ln((2/3)^(3/2)) 31 | ln(2^(3/2)) -> ln(2^(3/2)) 32 | log(13) -> log(13) 33 | tan(3*pi/2) -> tan(3*pi/2) 34 | ln(37) -> ln(37) 35 | ln(1/4) -> ln(1/4) 36 | ln(0-1) -> ln(0+(-1)) 37 | ln(0-1*x) -> ln(0+x*(-1)) 38 | -------------------------------------------------------------------------------- /src/tests/files/exponential/u_ops.txt: -------------------------------------------------------------------------------- 1 | tan(3*pi/2*x) -> tan(3*pi*(1/2)*x) 2 | atan(tan(x)) -> atan(tan(x)) 3 | asin(sin(x)) -> asin(sin(x)) 4 | acos(cos(2*ln(x))) -> acos(cos(2*ln(x))) 5 | atan(tan(5*pi/2)) -> atan(tan(5*pi*(1/2))) 6 | tan(0-3*pi/2) -> tan(0-3*pi*(1/2)) 7 | sec(0-3*pi/2) -> sec(0-3*pi*(1/2)) 8 | cot(pi) -> cot(pi) 9 | cot(0) -> cot(0) 10 | csc(0) -> csc(0) 11 | csc(100*pi) -> csc(100*pi) 12 | csc(pi/2) -> csc(pi*(1/2)) 13 | log(10) -> log(10) 14 | log(100) -> log(100) 15 | ln(225) -> ln(225) 16 | ln(e) -> ln(e) 17 | int(3.5) -> int(3.5) 18 | ln(e^3) -> ln(e^3) 19 | ln(e^3+x) -> ln(e^3+x) 20 | ln(e^3*x) -> ln(e^3*x) 21 | ln(x) -> ln(x) 22 | ln(e^(3*x)) -> ln(e^(3*x)) 23 | cos(pi) -> cos(pi) 24 | sin(pi) -> sin(pi) 25 | tan(pi) -> tan(pi) 26 | 100^log(5) -> 100^log(5) 27 | 1000^log(5) -> 1000^log(5) 28 | (e^3)^ln(3) -> (e^3)^ln(3) 29 | e^ln(5) -> e^ln(5) 30 | ln((2/3)^(3/2)) -> ln((2*(1/3))^(3*(1/2))) 31 | ln(2^(3/2)) -> ln(2^(3*(1/2))) 32 | log(13) -> log(13) 33 | tan(3*pi/2) -> tan(3*pi*(1/2)) 34 | ln(37) -> ln(37) 35 | ln(1/4) -> ln(1*(1/4)) 36 | ln(0-1) -> ln(0-1) 37 | ln(0-1*x) -> ln(0-1*x) 38 | -------------------------------------------------------------------------------- /src/jui/Label.java: -------------------------------------------------------------------------------- 1 | package jui; 2 | 3 | import processing.core.PConstants; 4 | 5 | //add public abstract void setValue(float val); 6 | //Jan 29th: deprecated all textHeight dividend variable in TextInput, Button, and Label. 7 | //TODO the adjustTextSize method should be replaced with a better one. April 22nd. 8 | public class Label extends Contextual { 9 | public Label(float x, float y, float w, float h) { 10 | super(x, y, w, h); 11 | init(); 12 | } 13 | 14 | public Label(float relativeW, float relativeH) { 15 | super(relativeW, relativeH); 16 | init(); 17 | } 18 | 19 | public Label() { 20 | super(); 21 | init(); 22 | } 23 | 24 | public Label(String content) { 25 | super(); 26 | init(); 27 | setContent(content); 28 | } 29 | 30 | public void init() { 31 | setTextMode(Mode.CONSTANT); 32 | setAlign(PConstants.LEFT); 33 | } 34 | 35 | 36 | public void display() { 37 | //drawing the background 38 | super.display(); /*modified April 22nd*/ 39 | displayText(); 40 | } 41 | 42 | @Override 43 | public Label setContent(String content) { 44 | super.setContent(content); 45 | return this; 46 | } 47 | 48 | @Override 49 | public Label setId(String id) { 50 | super.setId(id); 51 | return this; 52 | } 53 | 54 | @Override 55 | public Label clone() { 56 | return (Label) super.clone(); 57 | } 58 | } -------------------------------------------------------------------------------- /src/jas/extras/Element.java: -------------------------------------------------------------------------------- 1 | package jas.extras; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * Created by Jiachen on 9/12/17. 9 | * Element class that holds info for elements 10 | */ 11 | public enum Element { 12 | H(1, "Hydrogen", 1.008), 13 | He(2, "Helium", 4.003), 14 | Li(3, "Lithium", 6.941), 15 | C(6, "Carbon", 12.01), 16 | O(8, "Oxygen", 16.00), 17 | 18 | // ... 90+ others 19 | ; 20 | 21 | private final int atomicNumber; 22 | private final String fullName; 23 | private final double atomicMass; 24 | Element(int atomicNumber, String fullName, double atomicMass) { 25 | this.atomicNumber = atomicNumber; 26 | this.fullName = fullName; 27 | this.atomicMass = atomicMass; 28 | Holder.map.put(atomicNumber, this); 29 | } 30 | 31 | public static ArrayList getList() { 32 | ArrayList elements = new ArrayList<>(); 33 | Holder.map.values().forEach(elements::add); 34 | return elements; 35 | } 36 | 37 | public static Element forAtomicNumber(int atomicNumber) { 38 | return Holder.map.get(atomicNumber); 39 | } 40 | 41 | public int getAtomicNumber() { 42 | return atomicNumber; 43 | } 44 | 45 | public String getFullName() { 46 | return fullName; 47 | } 48 | 49 | public double getAtomicMass() { 50 | return atomicMass; 51 | } 52 | 53 | private static class Holder { 54 | static Map map = new HashMap<>(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/tests/specific/BinaryOperationTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.core.Compiler; 4 | import jas.core.components.RawValue; 5 | import jas.core.operations.Binary; 6 | import jas.core.operations.Operation; 7 | import tests.TestPrint; 8 | 9 | /** 10 | * Created by Jiachen on 3/7/18. 11 | * Binary Test 12 | */ 13 | public class BinaryOperationTest { 14 | public static void main(String args[]) { 15 | Binary binOp = new Binary(RawValue.ZERO, "*", RawValue.ONE); 16 | l(binOp.getRight(), binOp.getLeft()); 17 | binOp.setRight(RawValue.ONE); 18 | Binary.define("&", 3, (a, b) -> a + b); 19 | l(Binary.operators(), Binary.operators(3)); 20 | l(Binary.getPriority("&"), Binary.getPriority("+")); 21 | l(new Binary(RawValue.ZERO, "*", RawValue.ONE).getPriority()); 22 | l(new Binary(RawValue.ZERO, "*", RawValue.ONE).flattened()); 23 | l(binOp.is("*")); 24 | l(Operation.mult(3, 5)); 25 | l(Operation.exp(Math.random(), new RawValue(3))); 26 | l(Operation.exp(3, Math.random())); 27 | l(Compiler.compile("x+x*a").simplify()); 28 | ((Binary) Compiler.compile("x^b")).flattened().forEach(TestPrint::l); 29 | l(Operation.div(17, 4).setOperand(binOp.getOperand(1), 1).setOperands(binOp.getOperands())); 30 | l(Operation.div(3, 4).setLeft(new RawValue(5))); 31 | l(((Binary) Compiler.compile("a+b")).isCommutative()); 32 | l(Compiler.compile("a*c*d-1*-1")); 33 | } 34 | 35 | private static void l(Object... objects) { 36 | for (Object o : objects) { 37 | l(o); 38 | } 39 | } 40 | 41 | private static void l(Object o) { 42 | System.out.println(o); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/tests/specific/CustomOperationTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.core.Compiler; 4 | import jas.core.components.Constants; 5 | import jas.core.components.RawValue; 6 | import jas.core.components.Variable; 7 | import jas.core.operations.Argument; 8 | import jas.core.operations.Custom; 9 | import jas.core.operations.Manipulation; 10 | import jas.core.operations.Signature; 11 | 12 | import static tests.TestPrint.l; 13 | 14 | /** 15 | * Created by Jiachen on 3/17/18. 16 | * Composite Operation Test 17 | */ 18 | public class CustomOperationTest { 19 | public static void main(String args[]) { 20 | l(Compiler.compile("a+log(3+a)+4")); 21 | Custom co = (Custom) Compiler.compile("sum(4+7+5,5+x,log(7+cos(x)),x)"); 22 | l(co); //christ I finally did it!!! 23 | l(co.eval(5)); 24 | l(co.simplify()); 25 | l(RawValue.ONE.div(new Variable("x")).mult(Constants.E)); 26 | l(RawValue.ONE.negate().div(RawValue.ONE.sub(new Variable("x").sq()).sqrt())); 27 | 28 | // l(Compiler.compile("a+log(3+a)+4")); 29 | l(Argument.NUMBER.equals(Argument.ANY)); 30 | l(Argument.ANY.equals(Argument.NUMBER)); 31 | l(Argument.VARIABLE.equals(Argument.NUMBER)); 32 | l(Argument.NUMBER.equals(Argument.NUMBER)); 33 | l(Argument.OPERATION.equals(Argument.NUMBER)); 34 | l(Compiler.compile("expand(a*(b+c))").exec()); 35 | 36 | Custom.register(new Manipulation("custom", new Signature(Argument.ANY), operands -> { 37 | double calc = Math.log(operands.get(0).numNodes()); 38 | return new RawValue(calc); 39 | })); 40 | 41 | l(Compiler.compile("custom(x+b-c)").val()); 42 | Custom.unregister("custom", Signature.ANY); 43 | l(Compiler.compile("custom(x+b-c)").val()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/jas/core/operations/Signature.java: -------------------------------------------------------------------------------- 1 | package jas.core.operations; 2 | 3 | import jas.core.Node; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.Collections; 8 | import java.util.Optional; 9 | import java.util.stream.Collectors; 10 | 11 | /** 12 | * Created by Jiachen on 3/17/18. 13 | * Signature 14 | */ 15 | public class Signature { 16 | public static final Signature ANY = new Signature(); 17 | private Argument[] args; 18 | 19 | public Signature(Argument... args) { 20 | this.args = args; 21 | } 22 | 23 | public Signature(int numArgs) { 24 | args = new Argument[numArgs]; 25 | Arrays.fill(args, Argument.ANY); 26 | } 27 | 28 | private Signature(ArrayList args) { 29 | this(args.toArray(new Argument[args.size()])); 30 | } 31 | 32 | public boolean equals(Signature other) { 33 | if (args.length == 0 && other.args.length == 0) return true; // special case 34 | if (other.args.length != this.args.length) return false; 35 | for (int i = 0; i < args.length; i++) { 36 | if (!args[i].equals(other.args[i])) 37 | return false; 38 | } 39 | return true; 40 | } 41 | 42 | static Signature resolve(ArrayList args) { 43 | return new Signature(args.stream() 44 | .map(Argument::resolve) 45 | .collect(Collectors.toCollection(ArrayList::new))); 46 | } 47 | 48 | public String toString() { 49 | if (this.args == null || args.length == 0) return "ANY..."; 50 | ArrayList args = new ArrayList<>(); 51 | Collections.addAll(args, this.args); 52 | Optional str = args.stream().map(Enum::toString).reduce((a, b) -> a + ", " + b); 53 | return str.orElse(""); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/jas/core/Assets.java: -------------------------------------------------------------------------------- 1 | package jas.core; 2 | 3 | 4 | import jas.Function; 5 | import jas.core.operations.Binary; 6 | import jas.core.operations.Custom; 7 | import jas.core.operations.Manipulation; 8 | import jas.core.operations.Unary; 9 | 10 | import java.util.ArrayList; 11 | import java.util.stream.Collectors; 12 | 13 | /** 14 | * Created by Jiachen on 3/2/18. 15 | * Assets 16 | */ 17 | public interface Assets { 18 | String DIGITS = "0123456789."; 19 | String VARS = "abcdfghjklmnopqrstuvwxyz_"; 20 | String LETTERS = "abcdefghijklmnopqrstuvwxyz"; 21 | 22 | static String operators() { 23 | return Binary.operators(); 24 | } 25 | 26 | static String symbols() { 27 | return operators() + ",()<>'"; 28 | } 29 | 30 | static boolean isSymbol(char c) { 31 | return symbols().contains(Character.toString(c)); 32 | } 33 | 34 | static boolean isValidVarName(String s) { 35 | if (s.isEmpty()) { 36 | return false; 37 | } 38 | if (!Character.isJavaIdentifierStart(s.charAt(0))) { 39 | return false; 40 | } 41 | for (int i = 1; i < s.length(); i++) { 42 | if (!Character.isJavaIdentifierPart(s.charAt(i))) { 43 | return false; 44 | } 45 | } 46 | return true; 47 | } 48 | 49 | static ArrayList reservedNames() { 50 | ArrayList names = new ArrayList<>(); 51 | names.addAll(Unary.registeredOperations().stream() 52 | .map(Function::getName) 53 | .collect(Collectors.toCollection(ArrayList::new))); 54 | names.addAll(Custom.registeredManipulations().stream() 55 | .map(Manipulation::getName) 56 | .collect(Collectors.toCollection(ArrayList::new))); 57 | names.add("list"); 58 | return names; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/jas/core/components/Literal.java: -------------------------------------------------------------------------------- 1 | package jas.core.components; 2 | 3 | import jas.core.Mode; 4 | import jas.core.Node; 5 | import jas.utils.ColorFormatter; 6 | 7 | /** 8 | * Created by Jiachen on 3/23/18. 9 | * Literal: non-calculable nodes 10 | */ 11 | public class Literal extends Variable { 12 | private String content; 13 | 14 | public Literal(String content) { 15 | super(content); 16 | this.content = content; 17 | } 18 | 19 | @Override 20 | public boolean equals(Node other) { 21 | return other instanceof Literal && ((Literal) other).content.equals(content); 22 | } 23 | 24 | @Override 25 | public Literal copy() { 26 | return new Literal(content); 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "'" + content + "'"; 32 | } 33 | 34 | /** 35 | * If this method is successfully implemented, it would be marked as a milestone. 36 | * 37 | * @param v the variable in which the first derivative is taken with respect to. 38 | * @return first derivative of the expression 39 | */ 40 | @Override 41 | public Node firstDerivative(Variable v) { 42 | return RawValue.ZERO; 43 | } 44 | 45 | @Override 46 | public boolean isUndefined() { 47 | return false; 48 | } 49 | 50 | @Override 51 | public double eval(double x) { 52 | return Double.NaN; 53 | } 54 | 55 | @Override 56 | public String coloredString() { 57 | return ColorFormatter.color(this.toString(), Mode.LITERAL_COLOR); 58 | } 59 | 60 | public String get() { 61 | return content; 62 | } 63 | 64 | @Override 65 | public double val() { 66 | return Double.NaN; 67 | } 68 | 69 | @Override 70 | public Literal simplify() { 71 | return this; 72 | } 73 | 74 | @Deprecated 75 | public String getName() { 76 | return content; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/tests/specific/FractionTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.MathContext; 4 | import jas.core.Compiler; 5 | import jas.core.Node; 6 | import jas.core.components.Fraction; 7 | 8 | import java.math.BigInteger; 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.stream.Collectors; 12 | 13 | import static jas.utils.ColorFormatter.*; 14 | import static tests.TestPrint.l; 15 | 16 | /** 17 | * Created by Jiachen on 3/6/18. 18 | * Fraction Test class 19 | */ 20 | public class FractionTest { 21 | private static String ops[] = new String[]{ 22 | "3^-3", 23 | "(2/3)^(-1/3)", 24 | "3^(-1/3)", 25 | "(3/2)^(-2/3)", 26 | "7/8*2", 27 | "2/5+3/7", 28 | "2*5/7", 29 | "(3/4)*(5/7)", 30 | "3.5/4.7^2", 31 | "10^2.5" 32 | }; 33 | 34 | public static void main(String args[]) { 35 | l(Fraction.extractRoot(BigInteger.valueOf(350003000), BigInteger.valueOf(2))); 36 | l(MathContext.getFactors(35000)); 37 | 38 | Fraction f1 = new Fraction(3, 4); 39 | Fraction f2 = new Fraction(4, 3); 40 | f1.setNumerator(BigInteger.valueOf(100)) 41 | .setDenominator(BigInteger.valueOf(3)) 42 | .setDenominator(BigInteger.valueOf(5)) 43 | .setNumerator(BigInteger.valueOf(7)); 44 | l(f1.getNumerator(), f1.getDenominator()); 45 | 46 | 47 | Node o = f1.exp(f2); 48 | l(o); 49 | 50 | ArrayList raw = new ArrayList<>(); 51 | Collections.addAll(raw, ops); 52 | ArrayList nodes; 53 | nodes = (ArrayList) raw.stream().map(Compiler::compile).collect(Collectors.toList()); 54 | nodes.forEach(node -> l(node + " -> " + node.copy().simplify() + ", " 55 | + boldBlack("status: ") 56 | + ((node.val() - node.copy().simplify().val()) < 1E-10 ? lightGreen("PASSED") : lightRed("FAILED")))); 57 | 58 | // l(Fraction.extractRoot(-2,3)); 59 | l(((Fraction) Compiler.compile("3/4").simplify()).exp(-3)); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/CasController.java: -------------------------------------------------------------------------------- 1 | import javafx.application.Platform; 2 | import javafx.event.ActionEvent; 3 | import javafx.scene.control.Label; 4 | import javafx.scene.control.TextField; 5 | import javafx.scene.input.KeyEvent; 6 | 7 | /** 8 | * Created by Jiachen on 3/2/18. 9 | * CAS Controller 10 | */ 11 | public class CasController { 12 | 13 | 14 | public Label simplified; 15 | public TextField input; 16 | public Label beautified; 17 | public Label additionOnlyExp; 18 | public Label nodesBefore; 19 | public Label complexityBefore; 20 | public Label complexityAfter; 21 | public Label nodesAfter; 22 | public Label errMsg; 23 | public Label val; 24 | public Label vars; 25 | public Label expanded; 26 | 27 | @SuppressWarnings("unused") 28 | public void textFieldInput(KeyEvent keyEvent) { 29 | // System.out.println(keyEvent.getEventType()); 30 | simplified.setVisible(true); 31 | beautified.setVisible(true); 32 | additionOnlyExp.setVisible(true); 33 | nodesBefore.setVisible(true); 34 | complexityBefore.setVisible(true); 35 | complexityAfter.setVisible(true); 36 | nodesAfter.setVisible(true); 37 | errMsg.setVisible(true); 38 | val.setVisible(true); 39 | vars.setVisible(true); 40 | expanded.setVisible(true); 41 | // System.out.println(input.textProperty().get()); 42 | // System.out.println(input.textProperty().get()); 43 | } 44 | 45 | public void launchJGrapher(ActionEvent actionEvent) { 46 | System.out.println(actionEvent); 47 | Platform.runLater(() -> JGrapher.main(new String[]{"processing.awt.PGraphicsJava2D"})); 48 | } 49 | 50 | void error(String msg) { 51 | String str = "..."; 52 | // this.addition.setText(str); 53 | // this.exponential.setText(str); 54 | this.nodesBefore.setText(str); 55 | this.complexityBefore.setText(str); 56 | // this.simplified.setText(str); 57 | // this.beautified.setText(str); 58 | this.complexityAfter.setText(str); 59 | this.nodesAfter.setText(str); 60 | errMsg.setText(msg); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/tests/specific/NodeTest.java: -------------------------------------------------------------------------------- 1 | package tests.specific; 2 | 3 | import jas.core.Compiler; 4 | import jas.core.Node; 5 | import jas.core.operations.Operation; 6 | import jas.core.components.Variable; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.stream.Collectors; 11 | 12 | import static tests.TestPrint.l; 13 | 14 | /** 15 | * Created by Jiachen on 3/7/18. 16 | * Node Test 17 | */ 18 | public class NodeTest { 19 | private static String ops[] = new String[]{ 20 | "1*x", 21 | "0*x", 22 | "0^x", 23 | "x^0", 24 | "0^0", 25 | "1^0", 26 | "0/0", 27 | "x/0", 28 | "x/x", 29 | "x-0", 30 | "0+0", 31 | "0/1", 32 | "x+1", 33 | "x-1", 34 | "1^x", 35 | "0^1", 36 | "x^3^a", 37 | "(a*b)^3", 38 | "x^(x*3)^(1/3)" 39 | }; 40 | 41 | public static void main(String args[]) { 42 | ArrayList raw = new ArrayList<>(); 43 | Collections.addAll(raw, ops); 44 | ArrayList nodes; 45 | nodes = (ArrayList) raw.stream().map(Compiler::compile).collect(Collectors.toList()); 46 | l(Node.contains(nodes, Compiler.compile("0-x"))); 47 | l(Node.commonTerms(Compiler.compile("x*2*b*a*b*x^2/x"), Compiler.compile("b*x^2*b*x*1"))); 48 | l(Node.commonTerms(Compiler.compile("x"), Compiler.compile("b*x^2*b*x*1"))); 49 | l(Node.commonTerms(Compiler.compile("x"), Compiler.compile("b"))); 50 | l(new Variable("x").div(new Variable("p"))); 51 | l(new Variable("x").add(new Variable("p"))); 52 | l(new Variable("x").sub(new Variable("p"))); 53 | l(new Variable("x").mult(new Variable("p"))); 54 | l(new Variable("x").exp(new Variable("p"))); 55 | l(new Variable("x").negate()); 56 | l(Compiler.compile("(-1)*((2x^2)*a^(-1))").simplify().beautify()); 57 | Node o = Operation.div(12, 3); 58 | l(o.div(Math.random()).simplify()); 59 | l(Operation.div(new Variable("x"), new Variable("x"))); 60 | l(o.isNaN()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/jas/utils/ColorFormatter.java: -------------------------------------------------------------------------------- 1 | package jas.utils; 2 | 3 | import jui.JNode; 4 | 5 | /** 6 | * Created by Jiachen on 3/1/18. 7 | * ColorFormatter class whose job is to color the String for the system outputs. 8 | */ 9 | public class ColorFormatter { 10 | public static String boldBlack(Object o) { 11 | return color(o.toString(), "[1m"); 12 | } 13 | 14 | public static String color(String s, String modifier) { 15 | if (JNode.OS.toLowerCase().contains("windows")) return s; 16 | return (char) 27 + modifier + s + (char) 27 + "[0m"; 17 | } 18 | 19 | public static String lightRed(Object o) { 20 | return color(o.toString(), AnsiColor.LIGHT_RED.toString()); 21 | } 22 | 23 | public static String lightCyan(Object o) { 24 | return color(o.toString(), AnsiColor.LIGHT_CYAN.toString()); 25 | } 26 | 27 | public static String lightGreen(Object o) { 28 | return color(o.toString(), AnsiColor.LIGHT_GREEN.toString()); 29 | } 30 | 31 | public static String lightBlue(Object o) { 32 | return color(o.toString(), AnsiColor.LIGHT_BLUE.toString()); 33 | } 34 | 35 | public static String yellow(Object o) { 36 | return color(o.toString(), AnsiColor.YELLOW.toString()); 37 | } 38 | 39 | public static String purple(Object o) { 40 | return color(o.toString(), AnsiColor.PURPLE.toString()); 41 | } 42 | 43 | public static String lightPurple(Object o) { 44 | return color(o.toString(), AnsiColor.LIGHT_PURPLE.toString()); 45 | } 46 | 47 | /** 48 | * returns a colored line! 49 | * 50 | * @param modifier a sequence of escape characters for modifying the color& font. 51 | * @param line the line to be colored 52 | * @param symbols the symbols to be replaced with color 53 | * @return a beautifully formatted&colorful line for printing! 54 | * @since May 16th 55 | */ 56 | public static String coloredLine(String modifier, String line, String... symbols) { 57 | if (JNode.OS.toLowerCase().contains("windows")) 58 | return line; 59 | for (String symbol : symbols) { 60 | line = line.replace(symbol, (char) 27 + modifier + symbol + (char) 27 + "[0m"); 61 | } 62 | return line; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/jui/bundles/EnumSelector.java: -------------------------------------------------------------------------------- 1 | package jui.bundles; 2 | 3 | import jui.Button; 4 | import jui.HBox; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | 9 | /** 10 | * Created by Jiachen on 30/04/2017. 11 | */ 12 | public class EnumSelector extends HBox { 13 | private ArrayList