
(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 11 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)) (+ x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x + cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x + cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x + \cos y\right)
\end{array}
Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
sin-neg99.9%
fma-def99.9%
sin-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -0.0068) (+ x (cos y)) (if (<= x 2.1e+41) (- (cos y) (* z (sin y))) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.0068) {
tmp = x + cos(y);
} else if (x <= 2.1e+41) {
tmp = cos(y) - (z * sin(y));
} else {
tmp = 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 (x <= (-0.0068d0)) then
tmp = x + cos(y)
else if (x <= 2.1d+41) then
tmp = cos(y) - (z * sin(y))
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.0068) {
tmp = x + Math.cos(y);
} else if (x <= 2.1e+41) {
tmp = Math.cos(y) - (z * Math.sin(y));
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.0068: tmp = x + math.cos(y) elif x <= 2.1e+41: tmp = math.cos(y) - (z * math.sin(y)) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.0068) tmp = Float64(x + cos(y)); elseif (x <= 2.1e+41) tmp = Float64(cos(y) - Float64(z * sin(y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.0068) tmp = x + cos(y); elseif (x <= 2.1e+41) tmp = cos(y) - (z * sin(y)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.0068], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.1e+41], N[(N[Cos[y], $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0068:\\
\;\;\;\;x + \cos y\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+41}:\\
\;\;\;\;\cos y - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -0.00679999999999999962Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in z around 0 90.6%
+-commutative90.6%
Simplified90.6%
if -0.00679999999999999962 < x < 2.1e41Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 96.7%
if 2.1e41 < x Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around inf 84.4%
Final simplification92.7%
(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(x + Float64(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[(x + N[(N[Cos[y], $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\cos y - z \cdot \sin y\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.024) (not (<= y 1.8e-5))) (+ x (cos y)) (fma (- y) z (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.024) || !(y <= 1.8e-5)) {
tmp = x + cos(y);
} else {
tmp = fma(-y, z, (x + 1.0));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.024) || !(y <= 1.8e-5)) tmp = Float64(x + cos(y)); else tmp = fma(Float64(-y), z, Float64(x + 1.0)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.024], N[Not[LessEqual[y, 1.8e-5]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[((-y) * z + N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.024 \lor \neg \left(y \leq 1.8 \cdot 10^{-5}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, z, x + 1\right)\\
\end{array}
\end{array}
if y < -0.024 or 1.80000000000000005e-5 < y Initial program 99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in z around 0 62.0%
+-commutative62.0%
Simplified62.0%
if -0.024 < y < 1.80000000000000005e-5Initial program 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 99.6%
associate-+r+99.6%
+-commutative99.6%
mul-1-neg99.6%
Simplified99.6%
+-commutative99.6%
distribute-lft-neg-in99.6%
fma-def99.6%
Applied egg-rr99.6%
Final simplification82.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0235) (not (<= y 1.8e-5))) (+ x (cos y)) (- (+ x 1.0) (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0235) || !(y <= 1.8e-5)) {
tmp = x + cos(y);
} else {
tmp = (x + 1.0) - (z * 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 ((y <= (-0.0235d0)) .or. (.not. (y <= 1.8d-5))) then
tmp = x + cos(y)
else
tmp = (x + 1.0d0) - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0235) || !(y <= 1.8e-5)) {
tmp = x + Math.cos(y);
} else {
tmp = (x + 1.0) - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0235) or not (y <= 1.8e-5): tmp = x + math.cos(y) else: tmp = (x + 1.0) - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0235) || !(y <= 1.8e-5)) tmp = Float64(x + cos(y)); else tmp = Float64(Float64(x + 1.0) - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0235) || ~((y <= 1.8e-5))) tmp = x + cos(y); else tmp = (x + 1.0) - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0235], N[Not[LessEqual[y, 1.8e-5]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x + 1.0), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0235 \lor \neg \left(y \leq 1.8 \cdot 10^{-5}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) - z \cdot y\\
\end{array}
\end{array}
if y < -0.0235 or 1.80000000000000005e-5 < y Initial program 99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in z around 0 62.0%
+-commutative62.0%
Simplified62.0%
if -0.0235 < y < 1.80000000000000005e-5Initial program 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 99.6%
associate-+r+99.6%
+-commutative99.6%
mul-1-neg99.6%
Simplified99.6%
unsub-neg99.6%
*-commutative99.6%
Applied egg-rr99.6%
Final simplification82.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e-11) (not (<= x 10.8))) (+ x 1.0) (cos y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-11) || !(x <= 10.8)) {
tmp = x + 1.0;
} else {
tmp = 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 ((x <= (-1.55d-11)) .or. (.not. (x <= 10.8d0))) then
tmp = x + 1.0d0
else
tmp = cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-11) || !(x <= 10.8)) {
tmp = x + 1.0;
} else {
tmp = Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e-11) or not (x <= 10.8): tmp = x + 1.0 else: tmp = math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e-11) || !(x <= 10.8)) tmp = Float64(x + 1.0); else tmp = cos(y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.55e-11) || ~((x <= 10.8))) tmp = x + 1.0; else tmp = cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e-11], N[Not[LessEqual[x, 10.8]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[Cos[y], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-11} \lor \neg \left(x \leq 10.8\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;\cos y\\
\end{array}
\end{array}
if x < -1.55000000000000014e-11 or 10.800000000000001 < x Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in y around 0 82.0%
+-commutative82.0%
Simplified82.0%
if -1.55000000000000014e-11 < x < 10.800000000000001Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 99.1%
Taylor expanded in z around 0 64.8%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.6e-14) (not (<= x 4.5e-14))) (+ x 1.0) (- 1.0 (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.6e-14) || !(x <= 4.5e-14)) {
tmp = x + 1.0;
} else {
tmp = 1.0 - (z * 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 ((x <= (-6.6d-14)) .or. (.not. (x <= 4.5d-14))) then
tmp = x + 1.0d0
else
tmp = 1.0d0 - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.6e-14) || !(x <= 4.5e-14)) {
tmp = x + 1.0;
} else {
tmp = 1.0 - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.6e-14) or not (x <= 4.5e-14): tmp = x + 1.0 else: tmp = 1.0 - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.6e-14) || !(x <= 4.5e-14)) tmp = Float64(x + 1.0); else tmp = Float64(1.0 - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.6e-14) || ~((x <= 4.5e-14))) tmp = x + 1.0; else tmp = 1.0 - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.6e-14], N[Not[LessEqual[x, 4.5e-14]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{-14} \lor \neg \left(x \leq 4.5 \cdot 10^{-14}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;1 - z \cdot y\\
\end{array}
\end{array}
if x < -6.5999999999999996e-14 or 4.4999999999999998e-14 < x Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in y around 0 79.0%
+-commutative79.0%
Simplified79.0%
if -6.5999999999999996e-14 < x < 4.4999999999999998e-14Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in y around 0 57.6%
associate-+r+57.6%
+-commutative57.6%
mul-1-neg57.6%
Simplified57.6%
Taylor expanded in x around 0 57.5%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (if (<= y 2.25e+18) (- (+ x 1.0) (* z y)) (+ x 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.25e+18) {
tmp = (x + 1.0) - (z * y);
} else {
tmp = x + 1.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) :: tmp
if (y <= 2.25d+18) then
tmp = (x + 1.0d0) - (z * y)
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.25e+18) {
tmp = (x + 1.0) - (z * y);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.25e+18: tmp = (x + 1.0) - (z * y) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.25e+18) tmp = Float64(Float64(x + 1.0) - Float64(z * y)); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.25e+18) tmp = (x + 1.0) - (z * y); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.25e+18], N[(N[(x + 1.0), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.25 \cdot 10^{+18}:\\
\;\;\;\;\left(x + 1\right) - z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < 2.25e18Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in y around 0 79.0%
associate-+r+79.0%
+-commutative79.0%
mul-1-neg79.0%
Simplified79.0%
unsub-neg79.0%
*-commutative79.0%
Applied egg-rr79.0%
if 2.25e18 < y Initial program 99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around 0 34.4%
+-commutative34.4%
Simplified34.4%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (<= x -0.75) x (if (<= x 1.45e-9) 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.75) {
tmp = x;
} else if (x <= 1.45e-9) {
tmp = 1.0;
} else {
tmp = 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 (x <= (-0.75d0)) then
tmp = x
else if (x <= 1.45d-9) then
tmp = 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.75) {
tmp = x;
} else if (x <= 1.45e-9) {
tmp = 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.75: tmp = x elif x <= 1.45e-9: tmp = 1.0 else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.75) tmp = x; elseif (x <= 1.45e-9) tmp = 1.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.75) tmp = x; elseif (x <= 1.45e-9) tmp = 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.75], x, If[LessEqual[x, 1.45e-9], 1.0, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.75:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-9}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -0.75 or 1.44999999999999996e-9 < x Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around inf 81.1%
if -0.75 < x < 1.44999999999999996e-9Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 99.0%
Taylor expanded in y around 0 43.7%
Final simplification61.1%
(FPCore (x y z) :precision binary64 (+ x 1.0))
double code(double x, double y, double z) {
return x + 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 = x + 1.0d0
end function
public static double code(double x, double y, double z) {
return x + 1.0;
}
def code(x, y, z): return x + 1.0
function code(x, y, z) return Float64(x + 1.0) end
function tmp = code(x, y, z) tmp = x + 1.0; end
code[x_, y_, z_] := N[(x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
x + 1
\end{array}
Initial program 99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in y around 0 61.1%
+-commutative61.1%
Simplified61.1%
Final simplification61.1%
(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%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around 0 61.6%
Taylor expanded in y around 0 24.8%
Final simplification24.8%
herbie shell --seed 2023322
(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))))