cubing/alg

cubing/alg is the part of cubing.js that lets you parse and work with algs.

String conversion

Parse an alg by passing it to the Alg constructor. You can call .toString() to get back a string representation.

import { Alg } from "cubing/alg"

const alg = new Alg("R U R' U R U2' R'");
console.log(alg);
console.log(alg.toString());
Alg {} "R U R' U R U2' R'"

As a convenience, you can use .log() to view an alg in a JavaScript console (e.g. node or DevTools). We'll use that for all the examples from now on:

import { Alg } from "cubing/alg"

new Alg("R U R' U R U2' R'").log();
Alg {} "R U R' U R U2' R'"

Note that this will result in a canonical string for the alg with whitespace collapsed.

import { Alg } from "cubing/alg"

const alg = new Alg(" R   U R'   U R U2'   R'");
alg.log();
Alg {} "R U R' U R U2' R'"

Methods

Alg objects are immutable. In order to modify and Alg, you can call its methods:

import { Alg } from "cubing/alg";

const commutator = new Alg("[R, [U': L']]");
commutator.expand().log();
Alg {} "R U' L' U R' U' L U"

import { Alg } from "cubing/alg";
const commutator = new Alg("[R, [U': L']]");

const niklas = commutator.concat("U'");
niklas.log();
niklas.expand().log();
niklas.expand().simplify().log();
Alg {} "[R, [U': L']] U'" Alg {} "R U' L' U R' U' L U U'" Alg {} "R U' L' U R' U' L"

import { Alg } from "cubing/alg";

const sune = new Alg("[R U R2', [R: U]]");
const antiSune = sune.invert();
antiSune.log();
antiSune.expand().log();
Alg {} "[[R: U], R U R2']" Alg {} "R U2 R' U' R U' R'"

import { Alg } from "cubing/alg";
const antiSune = new Alg("[[R: U], R U R2']");
const niklas = new Alg("[R, [U': L']] U'");

const jPerm = antiSune.concat(niklas);
jPerm.log();
jPerm.expand().log();
jPerm.expand().simplify().log();
Alg {} "[[R: U], R U R2'] [R, [U': L']] U'" Alg {} "R U R' R U R2' R U' R' R2 U' R' R U' L' U R' U' L U U'" Alg {} "R U2 R' U' R U2' L' U R' U' L"

.expand() and .simplify() can also take options:

import { Alg } from "cubing/alg";

const oll = new Alg("[F: [R, U]]]");
oll.expand({depth: 1}).log();
Alg {} "F [R, U] F'"