
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Initial program 99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))))
(if (or (<= x -1.45e-10) (not (<= x 1.15e-19)))
(- (+ x 1.0) t_0)
(- (cos y) t_0))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double tmp;
if ((x <= -1.45e-10) || !(x <= 1.15e-19)) {
tmp = (x + 1.0) - t_0;
} else {
tmp = cos(y) - t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = z * sin(y)
if ((x <= (-1.45d-10)) .or. (.not. (x <= 1.15d-19))) then
tmp = (x + 1.0d0) - t_0
else
tmp = cos(y) - t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.sin(y);
double tmp;
if ((x <= -1.45e-10) || !(x <= 1.15e-19)) {
tmp = (x + 1.0) - t_0;
} else {
tmp = Math.cos(y) - t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) tmp = 0 if (x <= -1.45e-10) or not (x <= 1.15e-19): tmp = (x + 1.0) - t_0 else: tmp = math.cos(y) - t_0 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) tmp = 0.0 if ((x <= -1.45e-10) || !(x <= 1.15e-19)) tmp = Float64(Float64(x + 1.0) - t_0); else tmp = Float64(cos(y) - t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); tmp = 0.0; if ((x <= -1.45e-10) || ~((x <= 1.15e-19))) tmp = (x + 1.0) - t_0; else tmp = cos(y) - t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[x, -1.45e-10], N[Not[LessEqual[x, 1.15e-19]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
\mathbf{if}\;x \leq -1.45 \cdot 10^{-10} \lor \neg \left(x \leq 1.15 \cdot 10^{-19}\right):\\
\;\;\;\;\left(x + 1\right) - t\_0\\
\mathbf{else}:\\
\;\;\;\;\cos y - t\_0\\
\end{array}
\end{array}
if x < -1.4499999999999999e-10 or 1.1499999999999999e-19 < x Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites99.2%
if -1.4499999999999999e-10 < x < 1.1499999999999999e-19Initial program 99.9%
Taylor expanded in x around 0
lower-cos.f6499.9
Applied rewrites99.9%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.2e+20) (not (<= z 1.7e-10))) (- (+ x 1.0) (* z (sin y))) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e+20) || !(z <= 1.7e-10)) {
tmp = (x + 1.0) - (z * sin(y));
} else {
tmp = x + cos(y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-5.2d+20)) .or. (.not. (z <= 1.7d-10))) then
tmp = (x + 1.0d0) - (z * sin(y))
else
tmp = x + cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e+20) || !(z <= 1.7e-10)) {
tmp = (x + 1.0) - (z * Math.sin(y));
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.2e+20) or not (z <= 1.7e-10): tmp = (x + 1.0) - (z * math.sin(y)) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.2e+20) || !(z <= 1.7e-10)) tmp = Float64(Float64(x + 1.0) - Float64(z * sin(y))); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.2e+20) || ~((z <= 1.7e-10))) tmp = (x + 1.0) - (z * sin(y)); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.2e+20], N[Not[LessEqual[z, 1.7e-10]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+20} \lor \neg \left(z \leq 1.7 \cdot 10^{-10}\right):\\
\;\;\;\;\left(x + 1\right) - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -5.2e20 or 1.70000000000000007e-10 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites99.7%
if -5.2e20 < z < 1.70000000000000007e-10Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites72.5%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6472.4
lift--.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
Applied rewrites72.4%
Taylor expanded in z around 0
lower-+.f64N/A
lower-cos.f6499.4
Applied rewrites99.4%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.2e+71) (not (<= z 2.8e+78))) (* (- z) (sin y)) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.2e+71) || !(z <= 2.8e+78)) {
tmp = -z * sin(y);
} else {
tmp = x + cos(y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-8.2d+71)) .or. (.not. (z <= 2.8d+78))) then
tmp = -z * sin(y)
else
tmp = x + cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.2e+71) || !(z <= 2.8e+78)) {
tmp = -z * Math.sin(y);
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.2e+71) or not (z <= 2.8e+78): tmp = -z * math.sin(y) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.2e+71) || !(z <= 2.8e+78)) tmp = Float64(Float64(-z) * sin(y)); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.2e+71) || ~((z <= 2.8e+78))) tmp = -z * sin(y); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.2e+71], N[Not[LessEqual[z, 2.8e+78]], $MachinePrecision]], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{+71} \lor \neg \left(z \leq 2.8 \cdot 10^{+78}\right):\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -8.2000000000000004e71 or 2.8000000000000001e78 < z Initial program 99.8%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6474.4
Applied rewrites74.4%
if -8.2000000000000004e71 < z < 2.8000000000000001e78Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites78.2%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6478.0
lift--.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
Applied rewrites78.0%
Taylor expanded in z around 0
lower-+.f64N/A
lower-cos.f6494.6
Applied rewrites94.6%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.25) (not (<= y 5e+32))) (+ x (cos y)) (fma (- (* (fma 0.16666666666666666 (* z y) -0.5) y) z) y (+ 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.25) || !(y <= 5e+32)) {
tmp = x + cos(y);
} else {
tmp = fma(((fma(0.16666666666666666, (z * y), -0.5) * y) - z), y, (1.0 + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -3.25) || !(y <= 5e+32)) tmp = Float64(x + cos(y)); else tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), -0.5) * y) - z), y, Float64(1.0 + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.25], N[Not[LessEqual[y, 5e+32]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + -0.5), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.25 \lor \neg \left(y \leq 5 \cdot 10^{+32}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5\right) \cdot y - z, y, 1 + x\right)\\
\end{array}
\end{array}
if y < -3.25 or 4.9999999999999997e32 < y Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites71.9%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6471.7
lift--.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
Applied rewrites71.7%
Taylor expanded in z around 0
lower-+.f64N/A
lower-cos.f6463.5
Applied rewrites63.5%
if -3.25 < y < 4.9999999999999997e32Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6496.9
Applied rewrites96.9%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (<= y -4e+22) (+ 1.0 x) (- x (fma z y -1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+22) {
tmp = 1.0 + x;
} else {
tmp = x - fma(z, y, -1.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -4e+22) tmp = Float64(1.0 + x); else tmp = Float64(x - fma(z, y, -1.0)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -4e+22], N[(1.0 + x), $MachinePrecision], N[(x - N[(z * y + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+22}:\\
\;\;\;\;1 + x\\
\mathbf{else}:\\
\;\;\;\;x - \mathsf{fma}\left(z, y, -1\right)\\
\end{array}
\end{array}
if y < -4e22Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6442.9
Applied rewrites42.9%
if -4e22 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
lower--.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6471.3
Applied rewrites71.3%
(FPCore (x y z) :precision binary64 (+ 1.0 x))
double code(double x, double y, double z) {
return 1.0 + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + x
end function
public static double code(double x, double y, double z) {
return 1.0 + x;
}
def code(x, y, z): return 1.0 + x
function code(x, y, z) return Float64(1.0 + x) end
function tmp = code(x, y, z) tmp = 1.0 + x; end
code[x_, y_, z_] := N[(1.0 + x), $MachinePrecision]
\begin{array}{l}
\\
1 + x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6457.9
Applied rewrites57.9%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6457.9
Applied rewrites57.9%
Taylor expanded in x around 0
Applied rewrites22.2%
herbie shell --seed 2024318
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
:precision binary64
(- (+ x (cos y)) (* z (sin y))))