form 1 topics added

This commit is contained in:
2026-07-05 11:12:45 -04:00
parent a614532810
commit a23fa53772
58 changed files with 7089 additions and 475 deletions

View File

@@ -4,7 +4,7 @@ import { useState } from "react";
import { Card } from "@/components/ui/card";
import { StepControls } from "./step-controls";
import { MathDisplay } from "@/components/math/math-display";
import { toKatex, simplify, add, subtract, multiply, divide } from "@/lib/math/fractions";
import { toKatex, Fraction } from "@/lib/math/fractions";
interface FractionVal {
num: number;
@@ -30,24 +30,26 @@ const OP_PRIORITY: Record<string, number> = {
};
function performOp(a: FractionVal, b: FractionVal, op: string): FractionVal {
let result: [number, number];
const fa = new Fraction(a.num, a.den);
const fb = new Fraction(b.num, b.den);
let result: Fraction;
switch (op) {
case "+":
result = add(a.num, a.den, b.num, b.den);
result = fa.plus(fb);
break;
case "":
result = subtract(a.num, a.den, b.num, b.den);
result = fa.minus(fb);
break;
case "×":
result = multiply(a.num, a.den, b.num, b.den);
result = fa.times(fb);
break;
case "÷":
result = divide(a.num, a.den, b.num, b.den);
result = fa.dividedBy(fb);
break;
default:
result = [0, 1];
result = new Fraction(0, 1);
}
return { num: result[0], den: result[1] };
return { num: result.n, den: result.d };
}
function expressionToKatex(fracs: FractionVal[], ops: string[], highlightIdx: number | null): string {
@@ -97,7 +99,7 @@ function buildBodmasSteps(expr: Expression): Step[] {
// Perform the operation
const result = performOp(fracs[opIdx], fracs[opIdx + 1], ops[opIdx]);
const [sn, sd] = simplify(result.num, result.den);
const { n: sn, d: sd } = new Fraction(result.num, result.den).simplified();
const newFracs = [...fracs];
newFracs.splice(opIdx, 2, { num: sn, den: sd });