/usr/share/axiom-20140801/input/newtonlisp.input is in axiom-test 20140801-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | )set break resume
)sys rm -rf newtonlisp.output
)spool newtonlisp.output
)set message test on
)set message auto off
)clear all
)sys cp $AXIOM/../../src/input/newtonlisp.input.pamphlet .
)lisp (tangle "newtonlisp.input.pamphlet" "funcall.lisp" "funcall.lisp")
)lisp (compile-file "funcall.lisp")
)lisp (load "funcall.o")
)lisp (tangle "newtonlisp.input.pamphlet" "MKULF.spad" "MKULF.spad")
)co MKULF
)lisp (tangle "newtonlisp.input.pamphlet" "newton.lisp" "newton.lisp")
)lisp (compile-file "newton.lisp")
)lisp (load "newton.o")
)lisp (tangle "newtonlisp.input.pamphlet" "TESTP.spad" "TESTP.spad")
)co TESTP
)lisp (tangle "newtonlisp.input.pamphlet" "lispspad.lisp" "lispspad.lisp")
)lisp (compile-file "lispspad.lisp")
)lisp (load "lispspad.o")
)lisp (tangle "newtonlisp.input.pamphlet" "mklispfn.lisp" "mklispfn.lisp")
)lisp (compile-file "mklispfn.lisp")
)lisp (load "mklispfn.o")
)lisp (tangle "newtonlisp.input.pamphlet" "TESTP2.spad" "TESTP2.spad")
)co TESTP2
--S 1 of 14
R ==> Float
--R
--R Type: Void
--E 1
--S 2 of 14
I ==> Integer
--R
--R Type: Void
--E 2
--S 3 of 14
newton(f:Expression R,x:Symbol,x0:R):R ==
dfdx:Expression R := D(f,x)
xt:R := x0
fxt:R := subst(f,x=xt)
iterNum:I :=0
maxIt:I := 100
repeat
xt := xt - fxt/subst(dfdx,x=xt)
fxt := subst(f,x=xt)
if abs(fxt)<1.0e-10 then return xt
iterNum:=iterNum+1::I
if iterNum >= maxIt then
error "Maximum iterations exceeded."
--R
--R Function declaration newton : (Expression(Float),Symbol,Float) ->
--R Float has been added to workspace.
--R Type: Void
--E 3
--S 4 of 14
newton(x^2-2.0,x,2.0)
--R
--R Compiling function newton with type (Expression(Float),Symbol,Float)
--R -> Float
--R
--R (4) 1.4142135623 746899106
--R Type: Float
--E 4
--S 5 of 14
newton(y^2-2.0,y,2.0)
--R
--R
--R (5) 1.4142135623 746899106
--R Type: Float
--E 5
--S 6 of 14
newton(x^2-2.0,x,2.0)-sqrt(2.0)
--R
--R
--R (6) 0.15948618 E -11
--R Type: Float
--E 6
--S 7 of 14
compiledDF(expr: EXPR FLOAT, x:Symbol):Symbol ==
compiledFunction(expr,x)$MakeUnaryLispFunction(EXPR FLOAT,DFLOAT,DFLOAT)
--R
--R Function declaration compiledDF : (Expression(Float),Symbol) ->
--R Symbol has been added to workspace.
--R Type: Void
--E 7
--S 8 of 14
newtonUsingLisp(f:Expression Float,x:Symbol,x0:DFLOAT):DFLOAT ==
float(NEWTON(compiledDF(f,x),compiledDF(D(f,x),x),x0)$Lisp)
--R
--R Function declaration newtonUsingLisp : (Expression(Float),Symbol,
--R DoubleFloat) -> DoubleFloat has been added to workspace.
--R Type: Void
--E 8
--S 9 of 14
newtonUsingLisp(x**2-2.0,x,2.0::SF)-sqrt(2.0::SF)
--R
--R Compiling function compiledDF with type (Expression(Float),Symbol)
--R -> Symbol
--R Compiling function newtonUsingLisp with type (Expression(Float),
--R Symbol,DoubleFloat) -> DoubleFloat
--I Compiling function %A with type DoubleFloat -> DoubleFloat
--I Compiling function %B with type DoubleFloat -> DoubleFloat
--R
--R (9) 1.5947243525715749E-12
--R Type: DoubleFloat
--E 9
--S 10 of 14
float(NEWTON(lispFromSpad(f,'TestPackage,['DoubleFloat])$Lisp,_
lispFromSpad(dfdx,'TestPackage,['DoubleFloat])$Lisp,2::SF)$Lisp)_
-sqrt(2.0::SF)
--R
--R
--R (10) 1.5947243525715749E-12
--R Type: DoubleFloat
--E 10
--S 11 of 14
R ==> DoubleFloat
--R
--R Type: Void
--E 11
--S 12 of 14
newton((x:R):R +-> x^2-2.0::R,_
(x:R):R +-> 2.0::R*x, 3.0::SF, 1.0e-15, 100)$TestPackage2_
-sqrt(2.0)
--R
--R
--R (12) 0.
--R Type: DoubleFloat
--E 12
--S 13 of 14
newtonExpression(f,x,x0) ==
dfdx := D(f,x)
newton((xt:R):R +-> eval(f,x,xt), _
(xt:R):R +-> eval(dfdx,x,xt),x0)$TestPackage2
--R
--R Type: Void
--E 13
--S 14 of 14
newtonExpression(x^2-2.0,x,2.0)-sqrt(2.0)
--R
--R Compiling function newtonExpression with type (Polynomial(Float),
--R Variable(x),Float) -> DoubleFloat
--R
--R (14) 1.5949463971764999E-12
--R Type: DoubleFloat
--E 14
)spool
)lisp (bye)
|