diff --git a/elm-stuff/0.19.1/Fractions.elmi b/elm-stuff/0.19.1/Fractions.elmi new file mode 100644 index 0000000..fa61156 Binary files /dev/null and b/elm-stuff/0.19.1/Fractions.elmi differ diff --git a/elm-stuff/0.19.1/Fractions.elmo b/elm-stuff/0.19.1/Fractions.elmo new file mode 100644 index 0000000..dda0638 Binary files /dev/null and b/elm-stuff/0.19.1/Fractions.elmo differ diff --git a/elm-stuff/0.19.1/OverloadTest.elmi b/elm-stuff/0.19.1/OverloadTest.elmi new file mode 100644 index 0000000..3c47a81 Binary files /dev/null and b/elm-stuff/0.19.1/OverloadTest.elmi differ diff --git a/elm-stuff/0.19.1/OverloadTest.elmo b/elm-stuff/0.19.1/OverloadTest.elmo new file mode 100644 index 0000000..c3e157c Binary files /dev/null and b/elm-stuff/0.19.1/OverloadTest.elmo differ diff --git a/elm-stuff/0.19.1/ParserMaths.elmi b/elm-stuff/0.19.1/ParserMaths.elmi new file mode 100644 index 0000000..acd12a3 Binary files /dev/null and b/elm-stuff/0.19.1/ParserMaths.elmi differ diff --git a/elm-stuff/0.19.1/ParserMaths.elmo b/elm-stuff/0.19.1/ParserMaths.elmo new file mode 100644 index 0000000..f4dd32b Binary files /dev/null and b/elm-stuff/0.19.1/ParserMaths.elmo differ diff --git a/elm-stuff/0.19.1/QCM.elmo b/elm-stuff/0.19.1/QCM.elmo index 027b78e..7a15134 100644 Binary files a/elm-stuff/0.19.1/QCM.elmo and b/elm-stuff/0.19.1/QCM.elmo differ diff --git a/elm-stuff/0.19.1/d.dat b/elm-stuff/0.19.1/d.dat index 29f9b58..5432b3b 100644 Binary files a/elm-stuff/0.19.1/d.dat and b/elm-stuff/0.19.1/d.dat differ diff --git a/elm-stuff/0.19.1/i.dat b/elm-stuff/0.19.1/i.dat index f94a490..3f1cca2 100644 Binary files a/elm-stuff/0.19.1/i.dat and b/elm-stuff/0.19.1/i.dat differ diff --git a/elm-stuff/0.19.1/o.dat b/elm-stuff/0.19.1/o.dat index 5e931e4..c6edbbe 100644 Binary files a/elm-stuff/0.19.1/o.dat and b/elm-stuff/0.19.1/o.dat differ diff --git a/elm.json b/elm.json index 70e6ec9..3acf662 100644 --- a/elm.json +++ b/elm.json @@ -9,7 +9,8 @@ "elm/browser": "1.0.2", "elm/core": "1.0.5", "elm/html": "1.0.0", - "elm/parser": "1.1.0" + "elm/parser": "1.1.0", + "lynn/elm-arithmetic": "3.0.0" }, "indirect": { "elm/json": "1.1.3", diff --git a/src/Fractions.elm b/src/Fractions.elm new file mode 100644 index 0000000..6396b80 --- /dev/null +++ b/src/Fractions.elm @@ -0,0 +1,56 @@ +module Fractions exposing (..) + +import Arithmetic exposing (gcd) + +type alias Frac = { num : Int, den : Int } + +simplifier a = + let + pgcd = gcd a.num a.den + sgnDuDen = + if a.den < 0 then -1 else 1 + in + Frac (sgnDuDen*a.num // pgcd) (sgnDuDen*a.den // pgcd) + --{ a | num = a.num // pgcd, den = a.den // pgcd } + +estEntier a = .den (simplifier a) == 1 + +add a b = + simplifier <| Frac (a.num*b.den + a.den*b.num) (a.den*b.den) + +neg a = simplifier <| Frac (-a.num) a.den + +sub a b = simplifier <| add a (neg b) + +mul a b = simplifier <| Frac (a.num*b.num) (a.den*b.den) + +inv a = simplifier <| Frac a.den a.num + +div a b = simplifier <| mul a (inv b) + +exp : Frac -> Frac -> Maybe Frac +exp a b = + let + aa = simplifier a + bb = simplifier b + sgnDeA = + if aa.num < 0 then -1 else 1 + sgnDeB = + if bb.num < 0 then -1 else 1 + in + if bb.den == 1 && bb.num < 0 then + Just <| Frac ((sgnDeA*aa.den)^(sgnDeB*bb.num)) ((sgnDeA*aa.num)^(sgnDeB*bb.num)) + else if bb.den == 1 then + Just <| Frac (aa.num^bb.num) (aa.den^bb.num) + else + Nothing + +-- À utiliser sur une fraction simplifier ! +teX a + = case a.den of + 1 -> String.fromInt a.num + _ -> + if a.num < 0 then + "-\\frac{" ++ String.fromInt (-a.num) ++ "}{" ++ String.fromInt a.den ++ "}" + else + "\\frac{" ++ String.fromInt a.num ++ "}{" ++ String.fromInt a.den ++ "}" diff --git a/src/ParserMaths.elm b/src/ParserMaths.elm new file mode 100644 index 0000000..c8d6d4a --- /dev/null +++ b/src/ParserMaths.elm @@ -0,0 +1,236 @@ +module ParserMaths exposing (parseMaths, evaluer, montrerErreurs) + +import Fractions as F +import Maybe as M +import Parser exposing (..) + +montrerErreurs : String -> List DeadEnd -> String +montrerErreurs source errs = + case List.head errs of + Nothing -> + "" + + Just firstErr -> + source + ++ "\n" + ++ String.repeat (firstErr.col - 1) " " + ++ "^" + ++ "\nL'algorithme attendait :" + ++ String.join + " ou " + (List.map displayExpected errs) + + +displayExpected : DeadEnd -> String +displayExpected err = + case err.problem of + ExpectingNumber -> + "un nombre entier" + ExpectingSymbol s -> + "un \"" ++ s ++ "\"" + _ -> + "une expression" + + +evaluer : Expr -> Maybe F.Frac +evaluer expression = + case expression of + Add a b -> + M.map2 F.add (evaluer a) (evaluer b) + + Sub a b -> + M.map2 F.sub (evaluer a) (evaluer b) + + Mul a b -> + M.map2 F.mul (evaluer a) (evaluer b) + + Div a b -> + M.map2 F.div (evaluer a) (evaluer b) + + Exp a b -> + case M.map2 F.exp (evaluer a) (evaluer b) of + Nothing -> Nothing + Just p -> p + + Neg a -> + M.map F.neg (evaluer a) + + Grouping l -> + evaluer l + + Entier n -> + Just <| F.Frac n 1 + + +type Expr + = Add Expr Expr + | Sub Expr Expr + | Mul Expr Expr + | Div Expr Expr + | Exp Expr Expr + | Neg Expr + | Entier Int + | Grouping Expr + + +parseMaths : String -> Result (List DeadEnd) Expr +parseMaths source = + run expr source + + +expr : Parser Expr +expr = + add + + +type Operator + = MulOp + | DivOp + | AddOp + | SubOp + | ExpOp + + +type Operand + = NoOperand + | Operand Operator Expr + + +binary : Expr -> Operand -> Expr +binary a b = + case b of + NoOperand -> + a + + Operand op e -> + case op of + MulOp -> + Mul a e + + DivOp -> + Div a e + + AddOp -> + Add a e + + SubOp -> + Sub a e + + ExpOp -> + Exp a e + + +add : Parser Expr +add = + succeed + foldBinary + |= mul + |. spaces + |= loop [] addHelper + + +foldBinary : Expr -> List Operand -> Expr +foldBinary left operands = + List.foldr + (\operand expression -> binary expression operand) + left + operands + + +addHelper : List Operand -> Parser (Step (List Operand) (List Operand)) +addHelper operands = + oneOf + [ succeed (\right -> Loop (Operand AddOp right :: operands)) + |. symbol "+" + |. spaces + |= lazy (\_ -> mul) + , succeed (\right -> Loop (Operand SubOp right :: operands)) + |. symbol "-" + |. spaces + |= lazy (\_ -> mul) + , succeed () + |> map (\_ -> Done operands) + ] + + +mul : Parser Expr +mul = + succeed + foldBinary + |= exp + |. spaces + |= loop [] mulHelper + + +mulHelper : List Operand -> Parser (Step (List Operand) (List Operand)) +mulHelper operands = + oneOf + [ succeed (\right -> Loop (Operand MulOp right :: operands)) + |. symbol "*" + |. spaces + |= lazy (\_ -> exp) + , succeed (\right -> Loop (Operand DivOp right :: operands)) + |. symbol "/" + |. spaces + |= lazy (\_ -> exp) + , succeed () + |> map (\_ -> Done operands) + ] + + +exp : Parser Expr +exp = + succeed + binary + |= primary + |. spaces + |= oneOf + [ succeed (Operand ExpOp) + |. symbol "^" + |. spaces + |= lazy (\_ -> exp) + , succeed NoOperand + ] + + +primary : Parser Expr +primary = + succeed (\op literal -> + case op of + Nothing -> + literal + + Just _ -> + Neg literal + ) + |= oneOf + [ succeed Just + |= symbol "-" + , succeed Nothing + ] + |= oneOf + [ grouping + , nombre + ] + + +nombre : Parser Expr +nombre = + succeed Entier + |= number + { int = Just identity + , hex = Nothing + , octal = Nothing + , binary = Nothing + , float = Nothing + } + + +grouping : Parser Expr +grouping = + succeed Grouping + |. symbol "(" + |. spaces + |= lazy (\_ -> expr) + |. spaces + |. symbol ")" \ No newline at end of file diff --git a/src/QCM.elm b/src/QCM.elm index 185fab2..eaae4a9 100644 --- a/src/QCM.elm +++ b/src/QCM.elm @@ -3,7 +3,9 @@ module QCM exposing (..) import Browser import Parser as P exposing (Parser, (|.), (|=), succeed, symbol, float, spaces) import List as L +import ParserMaths as PM import String as S +import Fractions as F exposing (Frac) import Html exposing (Html, Attribute, button, div, input, text, p) import Html.Attributes exposing (..) import Html.Events exposing (onInput, onClick) @@ -81,6 +83,17 @@ view model = <| input [ placeholder "Format de la question", value model.question, onInput Question ] [] :: button [ onClick GenererQuestion ] [ text "Générer les questions" ] :: ( p [] <| L.map text model.questions ) + :: [ text + ( + let expressionParseePotentielle = PM.parseMaths "3+(2/3)^-2/3" + in + case expressionParseePotentielle of + Err erreur -> "L'expression est mal formée." + Ok expressionParsee -> + case Maybe.map F.teX <| PM.evaluer <| expressionParsee of + Just a -> a + Nothing -> "Les puissances non-entières ne sont pas acceptées." + ) ] {- , [ dl05 [0, 4, 2] 5 ] @@ -109,8 +122,8 @@ view model = , List.map dl04 ( mix [ [-5,-3,-1,1,3,5], [-6,-4,-2,2,4,6], [0], [-9,-8,-7,-6,-5,-4,-3,-2,-1] ] ) --324 possibilités Ok , List.concat <| List.map ( mapTwist [3,5,9] ) ( List.map dl05 ( mix [ [0], [2,4,7,8,11,13,16,17], [2,4,7,8,11,13,16,17] ] ) ) -- 192 possibilités OK , d3 -- 512 possibilités OK - -} :: ( List.map primitPoly01 <| mix [ List.range -3 -2 ++ List.range 2 3, List.range -3 -2 ++ List.range 2 3, List.range -3 -2 ++ List.range 2 3, List.range -3 -2 ++ List.range 2 3 ] ) -- 256 possibilités OK + -} {- @@ -161,10 +174,9 @@ texteSansVariables expressionVariable : Parser TexteVariable expressionVariable = succeed Variable - |. symbol "#(" - |= (P.getChompedString <| - succeed () - |. P.chompUntil "#") + |. symbol "#" + |= P.getChompedString ( P.chompUntil "#" ) + |. symbol "#" {-- testDeChomp diff --git a/src/QCMbis.elm b/src/QCMbis.elm deleted file mode 100644 index a806beb..0000000 --- a/src/QCMbis.elm +++ /dev/null @@ -1,583 +0,0 @@ -module QCMbis exposing (..) - --- Press buttons to increment and decrement a counter. --- --- Read how it works: --- https://guide.elm-lang.org/architecture/buttons.html --- - - -import Browser -import Html exposing (Html, button, div, text, p) -import Html.Events exposing (onClick) - - - --- MAIN - - -main = - Browser.sandbox { init = init, update = update, view = view } - - - --- MODEL - - -type alias Model = Int - - -init : Model -init = - 0 - - - --- UPDATE - - -type Msg - = Increment - | Decrement - - -update : Msg -> Model -> Model -update msg model = - case msg of - Increment -> - model + 1 - - Decrement -> - model - 1 - - - --- VIEW - - -view : Model -> Html Msg -view model = - div [] ( List.concat - [ - {-- - , [ dl10 [0, 4, 2] 5 ] - , [ text ( poly [0, 0, 7, -3, 0 , 2, 1 , -1 , 3 , 1, 1, 1, 5] ) ] - , [ primitPoly02 [2,-5,1,7] ] - , [ primitLn02 [-5,-6] ] - , [ equaDiff04 -5 ] - , [ equaDiff05 [4, -5] ] - , [ equaDiff06 [4, -5] ] - , [ derivPoly03 [4, -5, 3, 5, 13] ] - , [ derivPoly04 [-3, -4, 2, 7, -13] ] - , [ dl06 [-5, -2, 2, -1] ] - , [ dl07 [-5, 0, -2, -1] ] - , [ dl08 [0, -8, 0, 7] ] - , [ dl09 [-1, 2, 0, -3] ] - --} - List.map equaDiff04 <| List.range -9 -2 -- 98 possibilités - , List.map equaDiff05 ( mix [ [3,5,7], [-2,-4,-7,-8] ] ) -- 99 possibilités - , List.map equaDiff06 ( mix [ [3,5,7], [-2,-4,-7,-8] ] ) -- 99 possibilités - , List.map derivPoly03 ( mix [ [4,6], List.range -7 -6, List.range 2 3, List.range 11 12 ] ) -- 576 possibilités - , List.map derivPoly04 ( mix [ [-5,-3], [-4,-2], [2,6], List.range -14 -13 ] ) -- 256 possibilités - , List.map primitLn02 ( mix [ List.range -3 -2 ++ List.range 2 3, List.range -5 -4 ++ List.range 5 6 ] ) -- 256 possibilités - , List.map primitPoly02 ( mix [ List.range -3 -2 , List.range 2 3, List.range -5 -4 , List.range 6 7 ] ) -- 256 possibilités - , List.map dl06 ( mix [ [-3,5], [-2,6], [2,3], [-2,3] ] ) -- 648 possibilités - , List.map dl07 ( mix [ [-5,-2,2], [0], [-3,-4], [-2,3] ] ) -- 300 possibilités - , List.map dl08 ( mix [ [0], [-3,-2,2,3], [0], [2,3,4,5] ] ) -- 162 possibilités - , List.map dl09 ( mix [ [-5,3,5], [-6,4], [0], [-5,-3] ] ) --324 possibilités - , List.concat <| List.map ( mapTwist [3,5,9] ) ( List.map dl10 ( mix [ [0], [2,4], [7,8] ] ) ) -- 192 possibilités - , d3 -- 729 possibilités - ] - ) - -{-- -type Fonction num - = Const num - | X - | Poly List num - | Exp Fonction - | Ln Fonction - | Sin Fonction - | Cos Fonction ---} - - -mathTeX a = "$" ++ a ++ "$" - -fonction a = "x\\mapsto " ++ a - -affineExp a b c - = if (a,b) == (0,0) then "0" - else if (a,c) == (0,1) then String.fromInt b ++ "e^x" - else if a == 0 then String.fromInt b ++ "e^{" ++ (String.fromInt c) ++ "x}" - else if (a,b,c) == (1,0,1) then "xe^x" - else if (b,c) == (0,1) then (String.fromInt a) ++ "x" ++ "e^x" - else if b == 0 then (String.fromInt a) ++ "x" ++ "e^{" ++ (String.fromInt c) ++ "x}" - else if c == 1 then "\\left(" ++ (String.fromInt a) ++ "x+" ++ (String.fromInt b) ++ "\\right)e^x" - else "\\left(" ++ (String.fromInt a) ++ "x+" ++ (String.fromInt b) ++ "\\right)e^{" ++ (String.fromInt c) ++ "x}" - -derivExp02 a b c = - let - f aa bb cc = mathTeX ( fonction ( affineExp aa bb cc ) ) - vr aa bb cc = p [] [ text ( "+" ++ ( f aa bb cc) ) ] - fx aa bb cc = p [] [ text ( "-" ++ ( f aa bb cc) ) ] - in - div [] - [ p [] [ text ("Donner la dérivée de la fonction " ++ f a b c) ] - , vr (a*c) (a+b*c) c - , fx (a+b) a c - , fx (a+b) a c - , fx (a+b*c) (a*c) c - , fx (a-b*c) (a*c) c - , fx (a-b*c) (a*c) c - , fx a 0 c - , fx (a*c) 0 c - , fx a 0 1 - , fx (a*c) 0 1 - {-- - , p [] [ text ("----") ] - , p [] [ text ("Avant toute chose, il faut bien voir que $\\left(" ++ (String.fromInt a) ++ "x+" ++ (String.fromInt b) ++ "\\right)e^{" ++ (String.fromInt c) ++ "x}$ est de la forme $uv$ avec $u=ax+b$ et $v=e^{cx}$.") ], - , p [] [ text ("Ensuite, il faut savoir que la dérivée de $uv$ est donnée par $u'v+uv'$, et que la dérivée de $e^{u}$ est donnée par $e^{u}\\cdot u'$, ce qui dans notre cas nous donne que la dérivée de $e^{" ++ (String.fromInt c) ++ "x}$ est donnée par $" ++ (String.fromInt c) ++ "e^{" ++ (String.fromInt c) ++ "x}$.") ] - , p [] [ text ("Nous avons donc que la dérivée de la fonction est :") ] - , p [] [ text ("$\\begin{array}{rl} x\\mapsto & " ++ (String.fromInt (a)) ++ "e^{" ++ (String.fromInt c) ++ "x}+\\left(" ++ (String.fromInt (a)) ++ "x+" ++ (String.fromInt (b)) ++ "\\right)ce^{" ++ (String.fromInt (c)) ++ "x}\\\\& =" ++ (String.fromInt (a)) ++ "e^{" ++ (String.fromInt (c)) ++ "x}+\\left(" ++ (String.fromInt (a*c)) ++ "x+" ++ (String.fromInt (b*c)) ++ "\\right)e^{" ++ (String.fromInt (c)) ++ "x}\\\\ & =\\left(" ++ (String.fromInt (a)) ++ "+" ++ (String.fromInt (a*c)) ++ "x+" ++ (String.fromInt (b*c)) ++ "\\right)e^{" ++ (String.fromInt (c)) ++ "x}\\\\ & =\\left(" ++ (String.fromInt (a+b*c)) ++ "+" ++ (String.fromInt (a*c)) ++ "x\\right)e^{" ++ (String.fromInt (c)) ++ "x} \\end{array}$") ] - --} - , p [] [ text ("==== Dérivées, Exponentielle, derivExp02") ] - ] - - - --- Des DL - -monome a n = - if a == 0 then "" - else if n == 0 then ( String.fromInt a ) - else if (n,a) == (1,1) then "x" - else if (n,a) == (1,-1) then "-x" - else if n == 1 then ( String.fromInt a ) ++ "x" - else if a == 1 then "x^{" ++ ( String.fromInt n ) ++ "}" - else if a == -1 then "-x^{" ++ ( String.fromInt n ) ++ "}" - else ( String.fromInt a ) ++ "x^{" ++ ( String.fromInt n ) ++ "}" - -poly a_ks = - if a_ks == [] then "0" - else polyBis a_ks ( List.length a_ks - 1 ) - -polyBis a_ks n = - case a_ks of - [] -> "" - a_n :: a_kss -> - if a_n == 0 then polyBis a_kss ( n - 1 ) - else ( monome a_n n ) ++ ( polyGen a_kss ( n - 1 ) ) - -polyGen a_ks n = - case a_ks of - [] -> "" - a_i :: a_is -> - if a_i <= 0 then ( monome a_i n ) ++ ( polyGen a_is ( n - 1 ) ) - else "+" ++ ( monome a_i n ) ++ ( polyGen a_is ( n - 1 ) ) - -dl a_ks = - if a_ks == [] then "0" - else dlBis a_ks 0 - -dlBis a_ks n = - case a_ks of - [] -> "" - premierCoef :: suite -> - if premierCoef == 0 then dlBis suite ( n + 1 ) - else ( monome premierCoef n ) ++ ( dlGen suite ( n + 1 ) ) - -dlGen a_ks n = - case a_ks of - [] -> "" - a_i :: a_is -> - if a_i <= 0 then ( monome a_i n ) ++ ( dlGen a_is ( n + 1 ) ) - else "+" ++ ( monome a_i n ) ++ ( dlGen a_is ( n + 1 ) ) - -dl06 a_k = - let - vr texte = p [] [ text ( "+" ++ texte ) ] - fx texte = p [] [ text ( "-" ++ texte ) ] - in - div [] - [ p [] [ text ( "On considère une fonction $f$ dont le développement limité à l'ordre 3 au voisinage de $0$ est " ++ mathTeX ( dl a_k ) ++ "." ) ] - , p [] [ text ( "On note $C$ la courbe représentative de $f$ et $T_0$ sa tangente en son point d'abscisse $0$." ) ] - , p [] [ text ( "Cocher la ou les réponses correctes." ) ] - , vr <| "L'équation de $T_0$ est $y=" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $y=" ++ poly ( List.take 2 a_k ) ++"$" -- ATTENTION à éviter les cas où a_0 = a_1 - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.take 2 a_k ) ++"$" - , vr "$C$ est au-dessus de $T_0$." - , fx "$C$ est au-dessous de $T_0$." - , fx "$C$ est au-dessous puis au-dessus de $T_0$." - , fx "$C$ est au-dessus puis au-dessous de $T_0$." - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Développements limités, Tangentes, dl06") ] - ] - - -dl07 a_k = - let - vr texte = p [] [ text ( "+" ++ texte ) ] - fx texte = p [] [ text ( "-" ++ texte ) ] - in - div [] - [ p [] [ text ( "On considère une fonction $f$ dont le développement limité à l'ordre 3 au voisinage de $0$ est " ++ mathTeX ( dl a_k ) ++ "." ) ] - , p [] [ text ( "On note $C$ la courbe représentative de $f$ et $T_0$ sa tangente en son point d'abscisse $0$." ) ] - , p [] [ text ( "Cocher la ou les réponses correctes." ) ] - , vr <| "L'équation de $T_0$ est $y=" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , vr <| "L'équation de $T_0$ est $y=" ++ poly ( List.reverse <| List.take 3 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $y=" ++ poly ( List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.reverse <| List.take 3 a_k ) ++"x$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.take 2 a_k ) ++"$" - , fx "$C$ est au-dessus de $T_0$." - , vr "$C$ est au-dessous de $T_0$." - , fx "$C$ est au-dessous puis au-dessus de $T_0$." - , fx "$C$ est au-dessus puis au-dessous de $T_0$." - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Développements limités, Tangentes, dl07") ] - ] - - -dl08 a_k = - let - vr texte = p [] [ text ( "+" ++ texte ) ] - fx texte = p [] [ text ( "-" ++ texte ) ] - in - div [] - [ p [] [ text ( "On considère une fonction $f$ dont le développement limité à l'ordre 3 au voisinage de $0$ est " ++ mathTeX ( dl a_k ) ++ "." ) ] - , p [] [ text ( "On note $C$ la courbe représentative de $f$ et $T_0$ sa tangente en son point d'abscisse $0$." ) ] - , p [] [ text ( "Cocher la ou les réponses correctes." ) ] - , vr <| "L'équation de $T_0$ est $y=" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $y=" ++ poly ( List.take 2 a_k ) ++"$" -- ATTENTION à éviter les cas où a_0 = a_1 - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.take 2 a_k ) ++"$" - , fx "$C$ est au-dessus de $T_0$." - , fx "$C$ est au-dessous de $T_0$." - , vr "$C$ est au-dessous puis au-dessus de $T_0$." - , fx "$C$ est au-dessus puis au-dessous de $T_0$." - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Développements limités, Tangentes, dl08") ] - ] - - -dl09 a_k = - let - vr texte = p [] [ text ( "+" ++ texte ) ] - fx texte = p [] [ text ( "-" ++ texte ) ] - in - div [] - [ p [] [ text ( "On considère une fonction $f$ dont le développement limité à l'ordre 3 au voisinage de $0$ est " ++ mathTeX ( dl a_k ) ++ "." ) ] - , p [] [ text ( "On note $C$ la courbe représentative de $f$ et $T_0$ sa tangente en son point d'abscisse $0$." ) ] - , p [] [ text ( "Cocher la ou les réponses correctes." ) ] - , vr <| "L'équation de $T_0$ est $y=" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $y=" ++ poly ( List.take 2 a_k ) ++"$" -- ATTENTION à éviter les cas où a_0 = a_1 - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.reverse <| List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $f\\left(x\\right)\\approx" ++ poly ( List.take 2 a_k ) ++"$" - , fx <| "L'équation de $T_0$ est $" ++ poly ( List.take 2 a_k ) ++"$" - , fx "$C$ est au-dessus de $T_0$." - , fx "$C$ est au-dessous de $T_0$." - , fx "$C$ est au-dessous puis au-dessus de $T_0$." - , vr "$C$ est au-dessus puis au-dessous de $T_0$." - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Développements limités, Tangentes, dl09") ] - ] - - -dl10 a_k k = -- À n'utiliser qu'avec a_0 = 0 !!! - let - coefLin = - case a_k of - [] -> 0 - a_0 :: [] -> 0 - a_0 :: a_1 :: a_ks -> a_1 - coefQuad = - case a_k of - [] -> 0 - a_0 :: [] -> 0 - a_0 :: a_1 :: [] -> 0 - a_0 :: a_1 :: a_2 :: a_ks -> a_2 - vr a b = p [] [ text <| "+$\\frac{" ++ String.fromInt a ++ "}{" ++ String.fromInt b ++ "}$" ] - ffx a b = p [] [ text <| "-$\\frac{" ++ String.fromInt a ++ "}{" ++ String.fromInt b ++ "}$" ] - fx a = p [] [ text <| "-$" ++ String.fromInt a ++ "$" ] - in - div [] - [ p [] [ text ( "On considère une fonction $f$ dont le développement limité à l'ordre 2 au voisinage de $0$ est " ++ mathTeX ( dl a_k ) ++ "." ) ] - , p [] [ text <| "Que vaut $\\lim\\limits_{x\\to0}\\frac{f\\left(x\\right)}{" ++ (String.fromInt k) ++ "x}$" ] - , vr coefLin k - , ffx 1 coefLin - , ffx 1 coefQuad - , ffx 1 k - , ffx coefQuad k - , ffx k coefQuad - , fx coefLin - , fx coefQuad - , fx k - , fx 1 - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Développements limités, Tangentes, dl10") ] - ] - - -mapTwist a b = List.map b a - -entiers = List.range 2 4 - -d1 = List.map derivExp02 entiers - -d2 = List.concat ( List.map (mapTwist entiers) d1 ) - -d3 = List.concat ( List.map (mapTwist entiers) d2 ) - -mix lls = - case lls of - [] -> [] - [] :: llss -> [] - l :: [] -> List.map List.singleton l - (a :: ls) :: llss -> ( List.map ( (::) a ) ( mix llss ) ) ++ mix ( ls :: llss ) - -derivPoly03 param = -- on donne a pair et positif, les deux racines x_1 < x_2, d, et m > x_2 - case param of - [] -> div [] [] - a :: [] -> div [] [] - a :: b :: [] -> div [] [] - a :: b :: c :: [] -> div [] [] - a :: b :: c :: d :: [] -> div [] [] - a :: b :: c :: d :: e :: a_ks -> derivPoly03Bis a b c d e - -derivPoly03Bis a x_1 x_2 d m = - let - b = 0 - 3*a*(x_1 + x_2)//2 - c = 3*a*x_1*x_2 - a_k = [a,b,c,d] - vr texte = p [] [ text ( "+" ++ texte ) ] - fx texte = p [] [ text ( "-" ++ texte ) ] - in - div [] - [ p [] [ text ( "On considère la fonction $f:x\\mapsto " ++ ( poly a_k ) ++ "$." ) ] - , p [] [ text ( "Cocher la ou les réponses correctes." ) ] - , vr <| "La dérivée de $f$ est la fonction $f\\prime:x\\mapsto " ++ ( poly <| polyD a_k ) ++ "$." - , fx <| "La dérivée de $f$ est la fonction $f\\prime:x\\mapsto " ++ ( poly [3*a, 2*b, c + d] ) ++ "$." - , fx <| "la fonction $f$ est croissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";" ++ String.fromInt x_2 ++ "\\right]$" - , vr <| "la fonction $f$ est décroissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";" ++ String.fromInt x_2 ++ "\\right]$" - , fx <| "la fonction $f$ est décroissante sur l'intervalle $\\left[" ++ String.fromInt m ++ ";+\\infty\\right[$" - , vr <| "la fonction $f$ est croissante sur l'intervalle $\\left[" ++ String.fromInt m ++ ";+\\infty\\right[$" - , fx <| "la fonction $f$ est croissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";+\\infty\\right[$" - , fx <| "la fonction $f$ est décroissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";+\\infty\\right[$" - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Dérivée, Polynômes, derivPoly03") ] - ] - -derivPoly04 param = -- on donne a impair et négatif, les deux racines x_1 < x_2 pairs distincs, d, et m < x_1 - case param of - [] -> div [] [] - a :: [] -> div [] [] - a :: b :: [] -> div [] [] - a :: b :: c :: [] -> div [] [] - a :: b :: c :: d :: [] -> div [] [] - a :: b :: c :: d :: e :: a_ks -> derivPoly04Bis a b c d e - -derivPoly04Bis a x_1 x_2 d m = - let - b = 0 - 3*a*(x_1 + x_2)//2 - c = 3*a*x_1*x_2 - a_k = [a,b,c,d] - vr texte = p [] [ text ( "+" ++ texte ) ] - fx texte = p [] [ text ( "-" ++ texte ) ] - in - div [] - [ p [] [ text ( "On considère la fonction $f:x\\mapsto " ++ ( poly a_k ) ++ "$." ) ] - , p [] [ text ( "Cocher la ou les réponses correctes." ) ] - , vr <| "La dérivée de $f$ est la fonction $f\\prime:x\\mapsto " ++ ( poly <| polyD a_k ) ++ "$." - , fx <| "La dérivée de $f$ est la fonction $f\\prime:x\\mapsto " ++ ( poly [3*a, 2*b, c + d] ) ++ "$." - , vr <| "la fonction $f$ est croissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";" ++ String.fromInt x_2 ++ "\\right]$" - , fx <| "la fonction $f$ est décroissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";" ++ String.fromInt x_2 ++ "\\right]$" - , vr <| "la fonction $f$ est décroissante sur l'intervalle $\\left]-\\infty;" ++ String.fromInt m ++ "\\right]$" - , fx <| "la fonction $f$ est croissante sur l'intervalle $\\left]-\\infty;" ++ String.fromInt m ++ "\\right[$" - , fx <| "la fonction $f$ est croissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";+\\infty\\right[$" - , fx <| "la fonction $f$ est décroissante sur l'intervalle $\\left[" ++ String.fromInt x_1 ++ ";+\\infty\\right[$" - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Dérivée, Polynômes, derivPoly04") ] - ] - -polyD a_ks = polyDbis a_ks ( List.length a_ks - 1 ) - -polyDbis a_ks n = - case a_ks of - [] -> [] - a_0 :: [] -> [] - a_k :: a_kss -> ( n*a_k ) :: polyDbis a_kss ( n - 1 ) - -equaDiff04 a = -- a négatif - let - f aa = mathTeX ( fonction ( aa ) ) - vr aa = p [] [ text ( "+" ++ ( f aa ) ) ] - fx aa = p [] [ text ( "-" ++ ( f aa ) ) ] - in - div [] - [ p [] [ text <| "Parmi les fonctions ci-dessous, lesquelles sont des solutions de l'équation différentielle $y'=" ++ String.fromInt a ++ "y$ ?" ] - , vr <| String.fromInt ( a - 1 ) ++ "e^{" ++ String.fromInt a ++ "x}" - , vr <| String.fromInt ( a + 4 ) ++ "e^{" ++ String.fromInt a ++ "x}" - , vr <| String.fromInt a ++ "e^{" ++ String.fromInt a ++ "x}" - , fx <| String.fromInt a ++ "e^{" ++ String.fromInt (a-1) ++ "x}" - , fx <| String.fromInt ( a - 3 ) ++ "e^x" - , fx <| String.fromInt ( a + 7 ) ++ "e^x" ++ String.fromInt a - , fx <| String.fromInt a ++ "e^x" - , fx <| String.fromInt a ++ "e^x+" ++ String.fromInt ( a + 100) - , fx <| String.fromInt ( a - 1 ) ++ "e^x+" ++ String.fromInt ( a + 100) - , fx <| String.fromInt ( a - 8 ) ++ "e^{" ++ String.fromInt (a-1) ++ "x}" ++ String.fromInt a - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Équations différentielles, equaDiff04") ] - ] - -equaDiff05 param = - case param of - [] -> div [] [] - a :: [] -> div [] [] - a :: b :: c -> equaDiff05Bis a b - -equaDiff05Bis a b = -- a positif, b négatif, pas de simplification - let - f aa = mathTeX ( fonction ( aa ) ) - vr aa = p [] [ text ( "+" ++ ( f aa ) ) ] - fx aa = p [] [ text ( "-" ++ ( f aa ) ) ] - in - div [] - [ p [] [ text <| "Parmi les fonctions ci-dessous, lesquelles sont des solutions de l'équation différentielle $" ++ String.fromInt a ++"y'=" ++ String.fromInt b ++ "y$ ?" ] - , vr <| String.fromInt ( a - 17 ) ++ "e^{-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}x}" - , vr <| String.fromInt ( a + 23 ) ++ "e^{-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}x}" - , fx <| String.fromInt ( a + 3 ) ++ "e^{\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}x}" - , fx <| String.fromInt ( a - 17 ) ++ "e^{\\frac{" ++ String.fromInt a ++ "}{" ++ String.fromInt (0 - b) ++ "}x}" - , fx <| String.fromInt ( a + 23 ) ++ "e^{-\\frac{" ++ String.fromInt a ++ "}{" ++ String.fromInt (0 - b) ++ "}x}" - , fx <| String.fromInt a ++ "e^{" ++ String.fromInt b ++ "x}-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , fx <| String.fromInt a ++ "e^{" ++ String.fromInt b ++ "x}+\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , fx <| String.fromInt b ++ "e^{" ++ String.fromInt b ++ "x}-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , fx <| String.fromInt b ++ "e^{" ++ String.fromInt b ++ "x}+\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , fx <| "e^x+\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Équations différentielles, equaDiff05") ] - ] - -equaDiff06 param = - case param of - [] -> div [] [] - a :: [] -> div [] [] - a :: b :: c -> equaDiff06Bis a b - -equaDiff06Bis a b = -- a positif, b négatif, pas de simplification - let - f aa = mathTeX ( fonction ( aa ) ) - vr aa = p [] [ text ( "+" ++ ( f aa ) ) ] - fx aa = p [] [ text ( "-" ++ ( f aa ) ) ] - in - div [] - [ p [] [ text <| "Parmi les fonctions ci-dessous, lesquelles sont des solutions de l'équation différentielle $y'=" ++ String.fromInt a ++ "y" ++ String.fromInt b ++"$ ?" ] - , fx <| String.fromInt ( a - 17 ) ++ "e^{-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}x}" - , fx <| String.fromInt ( a + 23 ) ++ "e^{-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}x}" - , fx <| String.fromInt ( a + 3 ) ++ "e^{\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}x}" - , fx <| String.fromInt ( a - 17 ) ++ "e^{\\frac{" ++ String.fromInt a ++ "}{" ++ String.fromInt (0 - b) ++ "}x}" - , fx <| String.fromInt ( a + 23 ) ++ "e^{-\\frac{" ++ String.fromInt a ++ "}{" ++ String.fromInt (0 - b) ++ "}x}" - , fx <| String.fromInt a ++ "e^{" ++ String.fromInt a ++ "x}-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , vr <| String.fromInt a ++ "e^{" ++ String.fromInt a ++ "x}+\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , fx <| String.fromInt b ++ "e^{" ++ String.fromInt a ++ "x}-\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , vr <| String.fromInt b ++ "e^{" ++ String.fromInt a ++ "x}+\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - , fx <| "e^x+\\frac{" ++ String.fromInt (0 - b) ++ "}{" ++ String.fromInt a ++ "}" - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Équations différentielles, equaDiff06") ] - ] - -primitLn02 a_k = - case a_k of - [] -> div [] [] - a :: [] -> div [] [] - a :: b :: c -> primitLn02Bis a b - -primitLn02Bis a b = - let - f aa = mathTeX ( fonction ( aa ) ) - vr aa = p [] [ text ( "+" ++ ( f aa ) ) ] - fx aa = p [] [ text ( "-" ++ ( f aa ) ) ] - axpb = poly [a,b] - in - div [] - [ p [] [ text <| "Parmi les fonctions ci-dessous, lesquelles sont des primitives de la fonction " ++ ( f <| "\\frac{" ++ String.fromInt a ++ "}{" ++ axpb ++ "}" ) ++ " ?" ] - , vr <| "\\ln\\left(" ++ axpb ++ "\\right)" - , vr <| "\\ln\\left(" ++ axpb ++ "\\right)+" ++ String.fromInt ( b + 30 ) - , vr <| "\\ln\\left(" ++ axpb ++ "\\right)" ++ String.fromInt ( a - 20) - , fx <| "\\frac{" ++ String.fromInt (a*a) ++ "}{\\left(" ++ axpb ++ "\\right)^2}" - , fx <| "\\frac{" ++ String.fromInt (a*a) ++ "}{" ++ axpb ++ "}" ++ String.fromInt ( b + 30 ) - , fx <| "\\frac{" ++ String.fromInt (0 - a*a) ++ "}{\\left(" ++ axpb ++ "\\right)^2}" - , fx <| "\\frac{" ++ String.fromInt (0 - a*a) ++ "}{" ++ axpb ++ "}" ++ String.fromInt ( b + 30 ) - , fx <| "\\frac{" ++ String.fromInt (0 - a*a) ++ "}{" ++ axpb ++ "}" ++ String.fromInt ( a - 20) - , fx <| "\\frac{" ++ poly [a*a, a*b+a*a] ++ "}{\\left(" ++ axpb ++ "\\right)^2}" - , fx <| "\\frac{" ++ poly [a*a, a*b-a*a] ++ "}{\\left(" ++ axpb ++ "\\right)^2}" - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Primitives, Logarithme, primitLn02") ] - ] - -primitPoly02 a_k = - case a_k of - [] -> div [] [] - a :: [] -> div [] [] - a :: b :: [] -> div [] [] - a :: b :: c :: [] -> div [] [] - a :: b :: c :: d :: e -> primitPoly02Bis a b c d - -primitPoly02Bis a b c d = - let - pol = [a,b,c,d,0] - polD = polyD pol - polDD = polyD polD - f a_k = mathTeX ( fonction ( poly a_k ) ) - vr a_k = p [] [ text ( "+" ++ ( f a_k ) ) ] - fx a_k = p [] [ text ( "-" ++ ( f a_k ) ) ] - in - div [] - [ p [] [ text <| "Parmi les fonctions ci-dessous, lesquelles sont des primitives de la fonction " ++ ( f polD ) ++ " ?" ] - , vr <| List.map2 (+) pol [0,0,0,0,5] - , vr <| List.map2 (+) pol [0,0,0,0,-8] - , vr <| List.map2 (+) pol [0,0,0,0,8] - , fx <| List.map2 (+) polD [0,0,0,8] - , fx <| List.map2 (+) polD [0,0,0,-5] - , fx <| List.map2 (+) polD [0,0,0,-8] - , fx <| List.map2 (+) polDD [0,0,8] - , fx <| List.map2 (+) polDD [0,0,-5] - , fx <| List.map2 (+) polDD [0,0,-8] - {-- - , p [] [ text ("----") ] - --} - , p [] [ text ("==== Primitives, Polynômes, primitPoly02") ] - ] - - - -