From 2a6f7920bf9d6033ceb2bd4eb2382c4fe6cb3429 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 20 Dec 2018 00:38:50 +0000 Subject: [PATCH 1/6] Add help menu (no examples added yet) It features tons of musical references I'm sad that I didn't add any song of the king --- polymani.pl | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/polymani.pl b/polymani.pl index 8fa31c1..f767e0d 100644 --- a/polymani.pl +++ b/polymani.pl @@ -90,6 +90,61 @@ process_input(command(CL, TCR)) :- %% recurse process_input(TCR). +do_process_input(help_menu) :- + writeln("Please allow me to introduce myself"), + writeln("I'm a man[ual] of wealth and taste"), + writeln("I've been around for a long, long semester"), + writeln("Saved many a man's soul and faith"), + writeln("Pleased to meet you"), + writeln("Hope you guess my name"), + writeln("But what's puzzling you"), + writeln("Is the nature of my game"), + nl, + writeln("I'm a Polynomial Manipulator and the following commands are available:"), + writeln("=> Show - Allows to print a polynomial mathematically"), + writeln("=> Multiply - Allows to make multiplications"), + writeln("=> Simplify - Allows to simplify a given polynomial"), + writeln("=> Add - Allows to make sums"), + writeln("=> bye - Hello darkness, my old friend"), + writeln("Use 'tell me about {command}' to learn more about a specific command"), + nl, + writeln("Furthermore, I'm capable of memorizing polynomials during runtime. To learn more on that, type: tell me about storage"). +do_process_input(help(show)) :- + writeln("It's almost an echo of what you said, but a mathy one."), + writeln("Some example queries:"), + writeln(">"). +do_process_input(help(multiply)) :- + writeln("Multiplies a polynomial represented as an expression by a scalar resulting in a second polynomial. The two first arguments are assumed to be ground. The polynomial resulting from the sum is in simplified form."), + writeln("Some example queries:"), + writeln(">"). +do_process_input(help(simplify)) :- + writeln("Simplifies a polynomial represented as an expression as another polynomial as an expression."), + writeln("Some example queries:"), + writeln(">"). +do_process_input(help(add)) :- + writeln("Adds two polynomials as expressions resulting in a third one. The two first arguments are assumed to be ground. The polynomial resulting from the sum is in simplified form."), + writeln("Some example queries:"), + writeln(">"). +do_process_input(help(storage)) :- + writeln("Memories"), + writeln("All I have is memories"), + writeln("All I have is memories"), + writeln("Memories of polynomials"), + nl, + writeln("Storage manipulation is better illustrated with examples. Some example queries:"), + writeln("Asking me to memorize something:"), + writeln(">"), + nl, + writeln("Asking me to forget something:"), + writeln(">"), + nl, + writeln("Some examples of memory resources usage:"), + writeln(">"). +do_process_input(help(bye)) :- + writeln("There must be some kind of way outta here"), + writeln("Said the joker to the thief"), + writeln("There's too much confusion"), + writeln("I can't get no relief"). do_process_input(show_stored_polynomials) :- findall(nm(X,Y), polynomial_store(X,Y), D), nlp_print_memory(D). @@ -415,6 +470,13 @@ parse_polynomial_explicit(void-_, T) --> !, { T \= void }. +parse_command(help_menu) --> + [help]. +parse_command(help(C)) --> + [tell], + [me], + [about], + [C]. parse_command(show_stored_polynomials) --> [show, stored, polynomials]. parse_command(forget(P)) --> From 3a1602ff62aab24a7142fc2bb3b97d528959a792 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 20 Dec 2018 00:45:35 +0000 Subject: [PATCH 2/6] Replace Van Morrison with Elvis Presley - the king --- polymani.pl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/polymani.pl b/polymani.pl index 7d6a9e4..16730c0 100644 --- a/polymani.pl +++ b/polymani.pl @@ -136,10 +136,13 @@ do_process_input(help(add)) :- writeln("Some example queries:"), writeln(">"). do_process_input(help(storage)) :- - writeln("Memories"), - writeln("All I have is memories"), - writeln("All I have is memories"), - writeln("Memories of polynomials"), + writeln("Polynomials, pressed between the pages of my stack"), + writeln("olynomials, simplified through the ages just like predicates"), + writeln("Quiet goal come floating down"), + writeln("nd settle softly to the ground"), + writeln("Like golden atom leaves around my root"), + writeln(" touched them and they burst apart with sweet polynomials"), + writeln("Sweet polynomials"), nl, writeln("Storage manipulation is better illustrated with examples. Some example queries:"), writeln("Asking me to memorize something:"), From d9d835b00d3be5e870b4b1fd596aa4c7403f0328 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 20 Dec 2018 00:48:57 +0000 Subject: [PATCH 3/6] O Emacs fez das suas... --- polymani.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polymani.pl b/polymani.pl index 16730c0..11c5dd6 100644 --- a/polymani.pl +++ b/polymani.pl @@ -136,12 +136,12 @@ do_process_input(help(add)) :- writeln("Some example queries:"), writeln(">"). do_process_input(help(storage)) :- - writeln("Polynomials, pressed between the pages of my stack"), - writeln("olynomials, simplified through the ages just like predicates"), + writeln("Polynomials, pressed between the entries of my storage"), + writeln("Polynomials, simplified through the ages just like predicates"), writeln("Quiet goal come floating down"), - writeln("nd settle softly to the ground"), + writeln("And settle softly to the ground"), writeln("Like golden atom leaves around my root"), - writeln(" touched them and they burst apart with sweet polynomials"), + writeln("I touched them and they burst apart with sweet polynomials"), writeln("Sweet polynomials"), nl, writeln("Storage manipulation is better illustrated with examples. Some example queries:"), From 957e484db5fa696b5f9077df9a34b181877eb9b9 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 20 Dec 2018 01:10:35 +0000 Subject: [PATCH 4/6] Add minus --- polymani.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/polymani.pl b/polymani.pl index 11c5dd6..5854e02 100644 --- a/polymani.pl +++ b/polymani.pl @@ -298,10 +298,20 @@ parse_number_explicit(void, void, T, [WN | In], NC) :- member(P, [f, g, fy]), !, parse_number_explicit(P, N, T, In, NC). +parse_number_explicit(fy, NL, T, [WN | In], NC) :- + special_word_number(WN, N, f), + !, + parse_number_explicit(f, op(-, NL, N), T, In, NC). parse_number_explicit(fy, NL, T, [WN | In], NC) :- special_word_number(WN, N, f), !, parse_number_explicit(f, op(+, NL, N), T, In, NC). +parse_number_explicit(xfy, TL, T, [WN | In], NC) :- + TL \= void, + special_word_number(WN, N, P), + member(P, [f, g, fy]), + !, + parse_number_explicit(P, op(-, TL, N), T, In, NC). parse_number_explicit(xfy, TL, T, [WN | In], NC) :- TL \= void, special_word_number(WN, N, P), @@ -400,6 +410,7 @@ parse_power(TB) --> parse_polynomial_variable(TB). +parse_operation(-) --> [minus]. parse_operation(+) --> [plus]. parse_operation(*) --> [times]. @@ -473,6 +484,11 @@ parse_polynomial_explicit(void-_, T) --> parse_operation(Op), !, parse_polynomial_explicit(op(Op, TL, TRP)-TRP, T). +parse_polynomial_explicit(TLP-TL, T) --> + parse_polynomial_operand(TL), + parse_operation(-), + !, + parse_polynomial_explicit(op(-, TLP, TRP)-TRP, T). parse_polynomial_explicit(TLP-TL, T) --> parse_polynomial_operand(TL), parse_operation(+), @@ -539,6 +555,12 @@ parse_command(multiply(TN, TP)) --> parse_number(TN), [by], parse_polynomial(TP). +parse_command(op(-, TN, TP)) --> + [sub], + parse_polynomial(TN), + [X], + { member(X, [to, with]) }, + parse_polynomial(TP). parse_command(op(+, TN, TP)) --> [add], parse_polynomial(TN), From 2057d2b14f51c35f0d38b9652581255ac76322f8 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 20 Dec 2018 01:39:11 +0000 Subject: [PATCH 5/6] Make multiply great again --- polymani.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/polymani.pl b/polymani.pl index 5854e02..d1a4da8 100644 --- a/polymani.pl +++ b/polymani.pl @@ -210,7 +210,13 @@ do_process_input(simplify(PT)) :- do_process_input(multiply(TN, PT)) :- polynomial_tree_to_polynomial(TN, N), polynomial_tree_to_polynomial(PT, P), - scalepoly(N, P, P2), + ( + not(number(N)), + scalepoly(N, P, P2) + ; + number(N), + scalepoly(P, N, P2) + ), simpoly(P2, SP), write(SP), nl. @@ -552,7 +558,7 @@ parse_command(simplify(T)) --> parse_polynomial(T). parse_command(multiply(TN, TP)) --> [multiply], - parse_number(TN), + parse_polynomial(TN), [by], parse_polynomial(TP). parse_command(op(-, TN, TP)) --> From e48ededaa71519f89d22cc242f4186da86aed1a2 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 20 Dec 2018 02:22:38 +0000 Subject: [PATCH 6/6] Make as great again --- polymani.pl | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/polymani.pl b/polymani.pl index d1a4da8..33c3526 100644 --- a/polymani.pl +++ b/polymani.pl @@ -198,6 +198,14 @@ do_process_input(show(void, T)) :- polynomial_tree_to_polynomial(T, Pl), write(Pl), nl. +do_process_input(store_simplified(V,PTNS)) :- + polynomial_tree_to_polynomial(PTNS, PNS), + simpoly(PNS,P), + assertz(polynomial_store(V, P)), + write(V), + write(" = "), + write(P), + nl. do_process_input(store(P, T)) :- assertz(polynomial_store(P, T)). do_process_input(forget(P)) :- @@ -207,6 +215,22 @@ do_process_input(simplify(PT)) :- simpoly(P, SP), write(SP), nl. +do_process_input(store_multiplication(TN, PT, V)) :- + polynomial_tree_to_polynomial(TN, N), + polynomial_tree_to_polynomial(PT, P), + ( + not(number(N)), + scalepoly(N, P, P2) + ; + number(N), + scalepoly(P, N, P2) + ), + simpoly(P2, SP), + assertz(polynomial_store(V, SP)), + write(V), + write(" = "), + write(SP), + nl. do_process_input(multiply(TN, PT)) :- polynomial_tree_to_polynomial(TN, N), polynomial_tree_to_polynomial(PT, P), @@ -553,9 +577,21 @@ parse_command(store(P, T)) --> parse_polynomial(T), [as], parse_stored_variable(P). +parse_command(store_simplified(V, P)) --> + [simplify], + parse_polynomial(P), + [as], + [V]. parse_command(simplify(T)) --> [simplify], parse_polynomial(T). +parse_command(store_multiplication(TN, TP, V)) --> + [multiply], + parse_polynomial(TN), + [by], + parse_polynomial(TP), + [as], + [V]. parse_command(multiply(TN, TP)) --> [multiply], parse_polynomial(TN),