This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def relabel(xs, f): | |
| clazz = type(xs[0]) | |
| new_clazz = type(f"{clazz}_relabeled", (clazz,), {"__str__" : f}) | |
| for x in xs: | |
| x.__class__ = new_clazz | |
| def norms_abnorms(subgroups, G): | |
| norms = [] | |
| abnorms = [] | |
| for s in subgroups: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mi_dcg_clause, [] --> [natnum(0)]. | |
| mi_dcg_clause, [natnum(X)] --> [natnum(s(X))]. | |
| mi_dcg_clause, [always_infinite] --> [always_infinite]. | |
| mi_dcg --> []. | |
| mi_dcg --> mi_dcg_clause, mi_dcg. | |
| %% Original version from https://www.metalevel.at/acomip/ : | |
| mi_ldclause(natnum(0), Rest, Rest). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| accept(DCG, Xs) :- | |
| call(DCG, initial, Q), | |
| accept(DCG, Q, Xs, []). | |
| accept(DCG, Q, [], []) :- | |
| call(DCG, final, Q). | |
| accept(DCG, Q, [X|Xs], S) :- | |
| call(DCG, delta, Q, X, S, Q1, S1), | |
| accept(DCG, Q1, Xs, S1). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Void ( Void ) | |
| dneFalse :: ((Void -> Void) -> Void) -> Void | |
| dneFalse f = f id | |
| dneTrue :: ((() -> Void) -> Void) -> () | |
| dneTrue _ = () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :- use_module(library(reif)). | |
| phrase_t(P, I, O, T) :- phrase(call(P, T), I, O). | |
| if_(If, Then, Else, I, O) :- | |
| if_(phrase_t(If, I, M), | |
| phrase(Then, M, O), | |
| phrase(Else, M, O)). | |
| % Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| copy_term(VarsIn, In, VarsOut, Out) :- | |
| term_variables(In, AllVarsIn), | |
| maplist(list_to_ord_set, [AllVarsIn, VarsIn], [AllVarsInOrdSet, VarsInOrdSet]), | |
| ord_subtract(AllVarsInOrdSet, VarsInOrdSet, PreservedVars), | |
| copy_term(PreservedVars-VarsIn-In, PreservedVars-VarsOut-Out). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %! unifier(@Term1, @Term2, ?Unifier) is semidet. | |
| % | |
| % Like SWI Prolog's unifiable/3, but maintains the left-right order of the terms in the unifier, rather than placing variables on the left. | |
| unifier(A, B, Unifier) :- | |
| rb_empty(Seen), | |
| unifier_(Seen, A, B, [], Unifier0), | |
| exclude(unifier_is_reflexive, Unifier0, Unifier1), | |
| sort(Unifier1, Unifier). | |
| unifier_(Seen0, A, B, Unifier0, Unifier) :- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| foldargs(Goal, A, B) --> | |
| { maplist(functor_arity_term_args(_, _), [A, B], [As, Bs]) }, | |
| foldl(Goal, As, Bs). | |
| functor_arity_term_args(Functor, Arity, Term, Args) :- | |
| functor(Term, Functor, Arity), | |
| Term =.. [_|Args]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| unescape(\X, X). % Subterms, and in particular logic variables, can be marked as pre-evaluated. | |
| cata(Alg) --> unescape *-> {} ; mapargs(cata(Alg)), call(Alg). | |
| % Example: | |
| alg( 0 + 0, 0). | |
| alg( 0 + 1, 1). | |
| alg( 1 + 0, 1). | |
| alg( 1 + 12, 13). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from os import get_terminal_size | |
| from time import sleep | |
| terminal_size = get_terminal_size() | |
| num_cells = terminal_size.columns # We'll have as many cells as can fit in the terminal's width | |
| sleep_time = 4.0 / terminal_size.lines # Animation speed will be proportional to the terminal's height | |
| # Lookup table for Wolfram's "rule 30" cellular automaton | |
| RULE_30 = { | |
| (0,0,0) : 0, |