P-Adic numbers, basic: Difference between revisions
m
syntax highlighting fixup automation
(→{{header|Wren}}: Now uses new core library method.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 52:
=={{header|FreeBASIC}}==
<
' ***********************************************
'subject: convert two rationals to p-adic numbers,
Line 413:
system
</syntaxhighlight>
{{out|Examples}}
<pre>
Line 600:
=={{header|Go}}==
{{trans|FreeBASIC}}
<
import "fmt"
Line 929:
fmt.Println()
}
}</
{{out}}
Line 1,101:
p-Adic arithmetics and conversion between rationals is implemented as instances of <code>Eq</code>, <code>Num</code>, <code>Fractional</code> and <code>Real</code> classes, so, they could be treated as usual real numbers (up to existence of some rationals for non-prime bases).
<
module Padic where
Line 1,316:
let m = (x*r) `mod` p
_:zs = subMod p (x:xs) (mulMod p [m] (b:bs))
in m : go zs</
Convertation between rationals and p-adic numbers
Line 1,364:
Uses the Nemo abstract algebra library. The Nemo library's rational reconstruction function gives up quite easily,
so another alternative to FreeBasic's crat() using vector products is below.
<
set_printing_mode(FlintPadicField, :terse)
Line 1,426:
println(a, "\n", dstring(a), "\n", b, "\n", dstring(b), "\n+ =\n", c, "\n", dstring(c), " $r\n")
end
</
<pre>
2 + O(2^5)
Line 1,576:
{{trans|Go}}
Translation of Go with some modifications, especially using exceptions when an error is encountered.
<
const
Line 1,801:
echo ""
except PadicError:
echo getCurrentExceptionMsg()</
{{out}}
Line 1,967:
=={{header|Phix}}==
{{libheader|Phix/Class}}
<
constant EMX = 64 // exponent maximum (if indexing starts at -EMX)
constant DMX = 1e5 // approximation loop maximum
Line 2,234:
end if
printf(1,"\n")
end for</
{{out}}
<pre>
Line 2,259:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
#!/usr/bin/env raku
Line 2,353:
}
}
</syntaxhighlight>
{{out}}
<pre>
Line 2,364:
{{trans|FreeBASIC}}
{{libheader|Wren-dynamic}}
<
// constants
Line 2,637:
}
System.print()
}</
{{out}}
|