
(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 (- (+ 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%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -3.7e+28) x (if (<= x 1.75e-28) (- (cos y) (* z (sin y))) (+ x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.7e+28) {
tmp = x;
} else if (x <= 1.75e-28) {
tmp = cos(y) - (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 (x <= (-3.7d+28)) then
tmp = x
else if (x <= 1.75d-28) then
tmp = cos(y) - (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 (x <= -3.7e+28) {
tmp = x;
} else if (x <= 1.75e-28) {
tmp = Math.cos(y) - (z * Math.sin(y));
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.7e+28: tmp = x elif x <= 1.75e-28: tmp = math.cos(y) - (z * math.sin(y)) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.7e+28) tmp = x; elseif (x <= 1.75e-28) tmp = Float64(cos(y) - 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 (x <= -3.7e+28) tmp = x; elseif (x <= 1.75e-28) tmp = cos(y) - (z * sin(y)); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.7e+28], x, If[LessEqual[x, 1.75e-28], N[(N[Cos[y], $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{+28}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{-28}:\\
\;\;\;\;\cos y - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if x < -3.6999999999999999e28Initial program 100.0%
Taylor expanded in x around inf 83.1%
if -3.6999999999999999e28 < x < 1.75e-28Initial program 99.9%
Taylor expanded in x around 0 96.8%
if 1.75e-28 < x Initial program 99.9%
Taylor expanded in z around 0 83.6%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -5e+49) (not (<= z 5.5e+137))) (* z (- (sin y))) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5e+49) || !(z <= 5.5e+137)) {
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 <= (-5d+49)) .or. (.not. (z <= 5.5d+137))) 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 <= -5e+49) || !(z <= 5.5e+137)) {
tmp = z * -Math.sin(y);
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5e+49) or not (z <= 5.5e+137): tmp = z * -math.sin(y) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5e+49) || !(z <= 5.5e+137)) tmp = Float64(z * Float64(-sin(y))); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5e+49) || ~((z <= 5.5e+137))) tmp = z * -sin(y); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5e+49], N[Not[LessEqual[z, 5.5e+137]], $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 -5 \cdot 10^{+49} \lor \neg \left(z \leq 5.5 \cdot 10^{+137}\right):\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -5.0000000000000004e49 or 5.5000000000000002e137 < z Initial program 99.8%
Taylor expanded in z around inf 69.1%
associate-*r*69.1%
neg-mul-169.1%
*-commutative69.1%
Simplified69.1%
if -5.0000000000000004e49 < z < 5.5000000000000002e137Initial program 100.0%
Taylor expanded in z around 0 94.5%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.01) (not (<= y 0.00098))) (+ x (cos y)) (+ 1.0 (- x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.01) || !(y <= 0.00098)) {
tmp = x + cos(y);
} else {
tmp = 1.0 + (x - (y * z));
}
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.01d0)) .or. (.not. (y <= 0.00098d0))) then
tmp = x + cos(y)
else
tmp = 1.0d0 + (x - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.01) || !(y <= 0.00098)) {
tmp = x + Math.cos(y);
} else {
tmp = 1.0 + (x - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.01) or not (y <= 0.00098): tmp = x + math.cos(y) else: tmp = 1.0 + (x - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.01) || !(y <= 0.00098)) tmp = Float64(x + cos(y)); else tmp = Float64(1.0 + Float64(x - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.01) || ~((y <= 0.00098))) tmp = x + cos(y); else tmp = 1.0 + (x - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.01], N[Not[LessEqual[y, 0.00098]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.01 \lor \neg \left(y \leq 0.00098\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -0.0100000000000000002 or 9.7999999999999997e-4 < y Initial program 99.9%
Taylor expanded in z around 0 62.2%
if -0.0100000000000000002 < y < 9.7999999999999997e-4Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (<= x -3.6e-8) (+ x 1.0) (if (<= x 4.5e-13) (cos y) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e-8) {
tmp = x + 1.0;
} else if (x <= 4.5e-13) {
tmp = cos(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 (x <= (-3.6d-8)) then
tmp = x + 1.0d0
else if (x <= 4.5d-13) then
tmp = cos(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 (x <= -3.6e-8) {
tmp = x + 1.0;
} else if (x <= 4.5e-13) {
tmp = Math.cos(y);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.6e-8: tmp = x + 1.0 elif x <= 4.5e-13: tmp = math.cos(y) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.6e-8) tmp = Float64(x + 1.0); elseif (x <= 4.5e-13) tmp = cos(y); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.6e-8) tmp = x + 1.0; elseif (x <= 4.5e-13) tmp = cos(y); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.6e-8], N[(x + 1.0), $MachinePrecision], If[LessEqual[x, 4.5e-13], N[Cos[y], $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-8}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-13}:\\
\;\;\;\;\cos y\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -3.59999999999999981e-8 or 4.5e-13 < x Initial program 99.9%
Taylor expanded in y around 0 78.8%
+-commutative78.8%
Simplified78.8%
if -3.59999999999999981e-8 < x < 4.5e-13Initial program 99.9%
Taylor expanded in x around 0 99.3%
Taylor expanded in z around 0 69.1%
Final simplification73.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.24e+89) (+ x 1.0) (if (<= y 3.2) (+ 1.0 (- x (* y z))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.24e+89) {
tmp = x + 1.0;
} else if (y <= 3.2) {
tmp = 1.0 + (x - (y * z));
} 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 <= (-1.24d+89)) then
tmp = x + 1.0d0
else if (y <= 3.2d0) then
tmp = 1.0d0 + (x - (y * z))
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 <= -1.24e+89) {
tmp = x + 1.0;
} else if (y <= 3.2) {
tmp = 1.0 + (x - (y * z));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.24e+89: tmp = x + 1.0 elif y <= 3.2: tmp = 1.0 + (x - (y * z)) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.24e+89) tmp = Float64(x + 1.0); elseif (y <= 3.2) tmp = Float64(1.0 + Float64(x - Float64(y * z))); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.24e+89) tmp = x + 1.0; elseif (y <= 3.2) tmp = 1.0 + (x - (y * z)); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.24e+89], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 3.2], N[(1.0 + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.24 \cdot 10^{+89}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 3.2:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -1.2400000000000001e89 or 3.2000000000000002 < y Initial program 99.8%
Taylor expanded in y around 0 36.3%
+-commutative36.3%
Simplified36.3%
if -1.2400000000000001e89 < y < 3.2000000000000002Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
fma-def100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 89.9%
+-commutative89.9%
mul-1-neg89.9%
unsub-neg89.9%
Simplified89.9%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e-10) (+ x 1.0) (if (<= x 3.8e-35) (- 1.0 (* y z)) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e-10) {
tmp = x + 1.0;
} else if (x <= 3.8e-35) {
tmp = 1.0 - (y * z);
} 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 (x <= (-1.65d-10)) then
tmp = x + 1.0d0
else if (x <= 3.8d-35) then
tmp = 1.0d0 - (y * z)
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e-10) {
tmp = x + 1.0;
} else if (x <= 3.8e-35) {
tmp = 1.0 - (y * z);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.65e-10: tmp = x + 1.0 elif x <= 3.8e-35: tmp = 1.0 - (y * z) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.65e-10) tmp = Float64(x + 1.0); elseif (x <= 3.8e-35) tmp = Float64(1.0 - Float64(y * z)); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.65e-10) tmp = x + 1.0; elseif (x <= 3.8e-35) tmp = 1.0 - (y * z); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.65e-10], N[(x + 1.0), $MachinePrecision], If[LessEqual[x, 3.8e-35], N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-10}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-35}:\\
\;\;\;\;1 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -1.65e-10 or 3.8000000000000001e-35 < x Initial program 99.9%
Taylor expanded in y around 0 78.0%
+-commutative78.0%
Simplified78.0%
if -1.65e-10 < x < 3.8000000000000001e-35Initial program 99.9%
Taylor expanded in x around 0 99.5%
Taylor expanded in y around 0 54.2%
mul-1-neg54.2%
unsub-neg54.2%
Simplified54.2%
Final simplification65.4%
(FPCore (x y z) :precision binary64 (if (<= x -0.98) x (if (<= x 0.00018) 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.98) {
tmp = x;
} else if (x <= 0.00018) {
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.98d0)) then
tmp = x
else if (x <= 0.00018d0) 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.98) {
tmp = x;
} else if (x <= 0.00018) {
tmp = 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.98: tmp = x elif x <= 0.00018: tmp = 1.0 else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.98) tmp = x; elseif (x <= 0.00018) tmp = 1.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.98) tmp = x; elseif (x <= 0.00018) tmp = 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.98], x, If[LessEqual[x, 0.00018], 1.0, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.98:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 0.00018:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -0.97999999999999998 or 1.80000000000000011e-4 < x Initial program 99.9%
Taylor expanded in x around inf 77.1%
if -0.97999999999999998 < x < 1.80000000000000011e-4Initial program 99.9%
Taylor expanded in x around 0 98.3%
Taylor expanded in y around 0 44.6%
Final simplification59.3%
(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%
Taylor expanded in y around 0 60.5%
+-commutative60.5%
Simplified60.5%
Final simplification60.5%
(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 x around 0 64.1%
Taylor expanded in y around 0 25.7%
Final simplification25.7%
herbie shell --seed 2023185
(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))))