<commit_before>unit role MultiVector does Numeric;

# The grade projection should return a MultiVector
# except for grade zero where it should return a Real.
# This will make it easier to define the Real method.
multi method AT-POS(0) returns Real {...}
multi method AT-POS(UInt $n where $n > 0) returns MultiVector {...}

# The grades method should return a list of grades where
# the grade projection is not null.
# For instance (e0 + e0∧e1).grades should return 1, 2
method grades {...}

# conversion to Real as required by the Numeric role.
method Real {
    if any(self.grades) > 0 {
	fail X::Numeric::Real.new:
	target => Real,
	source => self,
	reason => 'Can not convert to Real: multivector is not purely scalar'
	;
    }
    return self[0] // 0;
}

method narrow returns Numeric {
    if self.grades == 0 { return 0 }
    elsif self.grades.any > 0 { return self }
    else { return self.Real.narrow }
}

proto method add($) returns MultiVector {*}
multi method add(Real $) {...}
multi method add(MultiVector $) {...}

proto method scale(Real $) {*}
multi method scale(0) { 0 }
multi method scale(1) returns MultiVector { self.clone }
multi method scale(Real $) returns MultiVector {...}

proto method gp(MultiVector $) returns MultiVector {*};
multi method gp(MultiVector $) {...};
proto method ip(MultiVector $) returns MultiVector {*};
multi method ip(MultiVector $) {...};<commit_msg>change Real conversion error message<commit_after>unit role MultiVector does Numeric;

# The grade projection should return a MultiVector
# except for grade zero where it should return a Real.
# This will make it easier to define the Real method.
multi method AT-POS(0) returns Real {...}
multi method AT-POS(UInt $n where $n > 0) returns MultiVector {...}

# The grades method should return a list of grades where
# the grade projection is not null.
# For instance (e0 + e0∧e1).grades should return 1, 2
method grades {...}

# conversion to Real as required by the Numeric role.
method Real {
    if any(self.grades) > 0 {
	fail X::Numeric::Real.new:
	target => Real,
	source => self,
	reason => 'not purely scalar'
	;
    }
    return self[0] // 0;
}

method narrow returns Numeric {
    if self.grades == 0 { return 0 }
    elsif self.grades.any > 0 { return self }
    else { return self.Real.narrow }
}

proto method add($) returns MultiVector {*}
multi method add(Real $) {...}
multi method add(MultiVector $) {...}

proto method scale(Real $) {*}
multi method scale(0) { 0 }
multi method scale(1) returns MultiVector { self.clone }
multi method scale(Real $) returns MultiVector {...}

proto method gp(MultiVector $) returns MultiVector {*};
multi method gp(MultiVector $) {...};
proto method ip(MultiVector $) returns MultiVector {*};
multi method ip(MultiVector $) {...};
{'fraction_non_alphanumeric': 0.12135397911415197, 'fraction_numerical': 0.011523226503420959, 'mean_word_length': 3.6925675675675675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2086918', 'n_tokens_mistral': 855, 'n_tokens_neox': 830, 'n_words': 333}