
(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 10 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 (+ (fma (- z) (sin y) (cos y)) x))
double code(double x, double y, double z) {
return fma(-z, sin(y), cos(y)) + x;
}
function code(x, y, z) return Float64(fma(Float64(-z), sin(y), cos(y)) + x) end
code[x_, y_, z_] := N[(N[((-z) * N[Sin[y], $MachinePrecision] + N[Cos[y], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, \sin y, \cos y\right) + x
\end{array}
Initial program 99.9%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.36e+79) (not (<= z 1.65e-68))) (- (+ x 1.0) (* z (sin y))) (+ (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.36e+79) || !(z <= 1.65e-68)) {
tmp = (x + 1.0) - (z * sin(y));
} else {
tmp = cos(y) + x;
}
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 <= (-1.36d+79)) .or. (.not. (z <= 1.65d-68))) then
tmp = (x + 1.0d0) - (z * sin(y))
else
tmp = cos(y) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.36e+79) || !(z <= 1.65e-68)) {
tmp = (x + 1.0) - (z * Math.sin(y));
} else {
tmp = Math.cos(y) + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.36e+79) or not (z <= 1.65e-68): tmp = (x + 1.0) - (z * math.sin(y)) else: tmp = math.cos(y) + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.36e+79) || !(z <= 1.65e-68)) tmp = Float64(Float64(x + 1.0) - Float64(z * sin(y))); else tmp = Float64(cos(y) + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.36e+79) || ~((z <= 1.65e-68))) tmp = (x + 1.0) - (z * sin(y)); else tmp = cos(y) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.36e+79], N[Not[LessEqual[z, 1.65e-68]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.36 \cdot 10^{+79} \lor \neg \left(z \leq 1.65 \cdot 10^{-68}\right):\\
\;\;\;\;\left(x + 1\right) - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y + x\\
\end{array}
\end{array}
if z < -1.36000000000000003e79 or 1.6499999999999999e-68 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites99.8%
if -1.36000000000000003e79 < z < 1.6499999999999999e-68Initial program 100.0%
Taylor expanded in x around inf
associate--l+N/A
div-subN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6499.9
Applied rewrites99.9%
Applied rewrites99.9%
Taylor expanded in z around 0
Applied rewrites99.6%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.5e+168) (not (<= z 3.3e+128))) (* (- z) (sin y)) (+ (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.5e+168) || !(z <= 3.3e+128)) {
tmp = -z * sin(y);
} else {
tmp = cos(y) + x;
}
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 <= (-2.5d+168)) .or. (.not. (z <= 3.3d+128))) then
tmp = -z * sin(y)
else
tmp = cos(y) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.5e+168) || !(z <= 3.3e+128)) {
tmp = -z * Math.sin(y);
} else {
tmp = Math.cos(y) + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.5e+168) or not (z <= 3.3e+128): tmp = -z * math.sin(y) else: tmp = math.cos(y) + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.5e+168) || !(z <= 3.3e+128)) tmp = Float64(Float64(-z) * sin(y)); else tmp = Float64(cos(y) + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.5e+168) || ~((z <= 3.3e+128))) tmp = -z * sin(y); else tmp = cos(y) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.5e+168], N[Not[LessEqual[z, 3.3e+128]], $MachinePrecision]], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+168} \lor \neg \left(z \leq 3.3 \cdot 10^{+128}\right):\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y + x\\
\end{array}
\end{array}
if z < -2.49999999999999983e168 or 3.3000000000000001e128 < 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.f6475.9
Applied rewrites75.9%
if -2.49999999999999983e168 < z < 3.3000000000000001e128Initial program 100.0%
Taylor expanded in x around inf
associate--l+N/A
div-subN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6499.4
Applied rewrites99.4%
Applied rewrites96.3%
Taylor expanded in z around 0
Applied rewrites90.3%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 2.5e-12))) (+ (cos y) x) (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 <= -0.5) || !(y <= 2.5e-12)) {
tmp = cos(y) + x;
} 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 <= -0.5) || !(y <= 2.5e-12)) tmp = Float64(cos(y) + x); else tmp = fma(fma(Float64(Float64(Float64(0.16666666666666666 * z) * y) - 0.5), y, Float64(-z)), y, Float64(1.0 + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 2.5e-12]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(N[(N[(0.16666666666666666 * z), $MachinePrecision] * y), $MachinePrecision] - 0.5), $MachinePrecision] * y + (-z)), $MachinePrecision] * y + N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\right):\\
\;\;\;\;\cos y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(0.16666666666666666 \cdot z\right) \cdot y - 0.5, y, -z\right), y, 1 + x\right)\\
\end{array}
\end{array}
if y < -0.5 or 2.49999999999999985e-12 < y Initial program 99.9%
Taylor expanded in x around inf
associate--l+N/A
div-subN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6490.9
Applied rewrites90.9%
Applied rewrites90.9%
Taylor expanded in z around 0
Applied rewrites65.0%
if -0.5 < y < 2.49999999999999985e-12Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (<= x -3.45e-13) (+ 1.0 x) (if (<= x 2.2e-19) (fma (- z) y 1.0) (- x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.45e-13) {
tmp = 1.0 + x;
} else if (x <= 2.2e-19) {
tmp = fma(-z, y, 1.0);
} else {
tmp = x - (z * y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.45e-13) tmp = Float64(1.0 + x); elseif (x <= 2.2e-19) tmp = fma(Float64(-z), y, 1.0); else tmp = Float64(x - Float64(z * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.45e-13], N[(1.0 + x), $MachinePrecision], If[LessEqual[x, 2.2e-19], N[((-z) * y + 1.0), $MachinePrecision], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.45 \cdot 10^{-13}:\\
\;\;\;\;1 + x\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot y\\
\end{array}
\end{array}
if x < -3.44999999999999994e-13Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6484.3
Applied rewrites84.3%
if -3.44999999999999994e-13 < x < 2.1999999999999998e-19Initial program 99.9%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f6455.0
Applied rewrites55.0%
Taylor expanded in x around 0
Applied rewrites55.0%
Taylor expanded in y around 0
Applied rewrites55.7%
if 2.1999999999999998e-19 < x Initial program 99.9%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f6457.5
Applied rewrites57.5%
Taylor expanded in x around 0
Applied rewrites57.6%
Taylor expanded in z around inf
Applied rewrites74.3%
(FPCore (x y z) :precision binary64 (if (<= x -5.2e+48) (+ 1.0 x) (+ (fma (- z) y 1.0) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+48) {
tmp = 1.0 + x;
} else {
tmp = fma(-z, y, 1.0) + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.2e+48) tmp = Float64(1.0 + x); else tmp = Float64(fma(Float64(-z), y, 1.0) + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -5.2e+48], N[(1.0 + x), $MachinePrecision], N[(N[((-z) * y + 1.0), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+48}:\\
\;\;\;\;1 + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 1\right) + x\\
\end{array}
\end{array}
if x < -5.1999999999999999e48Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6488.4
Applied rewrites88.4%
if -5.1999999999999999e48 < x Initial program 99.9%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6463.7
Applied rewrites63.7%
(FPCore (x y z) :precision binary64 (if (<= x -5.2e+48) (+ 1.0 x) (fma (- z) y (+ 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.2e+48) {
tmp = 1.0 + x;
} else {
tmp = fma(-z, y, (1.0 + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.2e+48) tmp = Float64(1.0 + x); else tmp = fma(Float64(-z), y, Float64(1.0 + x)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -5.2e+48], N[(1.0 + x), $MachinePrecision], N[((-z) * y + N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+48}:\\
\;\;\;\;1 + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 1 + x\right)\\
\end{array}
\end{array}
if x < -5.1999999999999999e48Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6488.4
Applied rewrites88.4%
if -5.1999999999999999e48 < x Initial program 99.9%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-+.f6463.7
Applied rewrites63.7%
(FPCore (x y z) :precision binary64 (if (<= z -2.6e+168) (- x (* z y)) (+ 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.6e+168) {
tmp = x - (z * y);
} else {
tmp = 1.0 + x;
}
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 <= (-2.6d+168)) then
tmp = x - (z * y)
else
tmp = 1.0d0 + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.6e+168) {
tmp = x - (z * y);
} else {
tmp = 1.0 + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.6e+168: tmp = x - (z * y) else: tmp = 1.0 + x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.6e+168) tmp = Float64(x - Float64(z * y)); else tmp = Float64(1.0 + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.6e+168) tmp = x - (z * y); else tmp = 1.0 + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.6e+168], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision], N[(1.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+168}:\\
\;\;\;\;x - z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 + x\\
\end{array}
\end{array}
if z < -2.6e168Initial program 99.7%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f6455.1
Applied rewrites55.1%
Taylor expanded in x around 0
Applied rewrites55.1%
Taylor expanded in z around inf
Applied rewrites52.1%
if -2.6e168 < z Initial program 100.0%
Taylor expanded in y around 0
lower-+.f6467.8
Applied rewrites67.8%
(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-+.f6462.4
Applied rewrites62.4%
(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-+.f6462.4
Applied rewrites62.4%
Taylor expanded in x around 0
Applied rewrites22.6%
herbie shell --seed 2024326
(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))))