----------------------------------------------------------------------------- -- Copyright 2015, Open Universiteit Nederland. This file is distributed -- under the terms of the GNU General Public License. For more information, -- see the file "LICENSE.txt", which is included in the distribution. ----------------------------------------------------------------------------- -- | -- Maintainer : bastiaan.heeren@ou.nl -- Stability : provisional -- Portability : portable (depends on ghc) -- ----------------------------------------------------------------------------- -- $Id: Exercises.hs 7527 2015-04-08 07:58:06Z bastiaan $ module Domain.Math.Fraction.Exercises ( simpleFractionAddition ) where import Domain.Math.Expr import Domain.Math.Fraction.Rules import Domain.Math.Fraction.Strategies import Domain.Math.Numeric.Views import Ideas.Common.Library import Ideas.Common.Utils.Uniplate simpleFractionAddition :: Exercise Expr simpleFractionAddition = makeExercise { status = Alpha , exerciseId = describe "Fraction exercise for STEPS" $ newId "arithmetic.fractions.steps" , parser = parseExpr , strategy = expandAndAdd , navigation = termNavigator , equivalence = withoutContext areEqual , extraRules = map use [gcdRule, lcmRule, expandRule, reduceRule] } areEqual :: Expr -> Expr -> Bool areEqual = viewEquivalent (extraSymbols >>> rationalView) -- This view handles the reduce and expand symbols for the euquivalence test. -- Semantically, reduce(a,b) = a. extraSymbols :: View Expr Expr extraSymbols = makeView (Just . f) id where f expr = case getFunction expr of Just (s, [x, _]) | s == reduceFractionSymbol -> f x | s == expandFractionSymbol -> f x _ -> descend f expr