
(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 (let* ((t_0 (* z (sin y)))) (if (or (<= x -1.0) (not (<= x 0.95))) (- x 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.0) || !(x <= 0.95)) {
tmp = x - 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.0d0)) .or. (.not. (x <= 0.95d0))) then
tmp = x - 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.0) || !(x <= 0.95)) {
tmp = x - 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.0) or not (x <= 0.95): tmp = x - 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.0) || !(x <= 0.95)) tmp = Float64(x - 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.0) || ~((x <= 0.95))) tmp = x - 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.0], N[Not[LessEqual[x, 0.95]], $MachinePrecision]], N[(x - 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 \lor \neg \left(x \leq 0.95\right):\\
\;\;\;\;x - t_0\\
\mathbf{else}:\\
\;\;\;\;\cos y - t_0\\
\end{array}
\end{array}
if x < -1 or 0.94999999999999996 < x Initial program 99.9%
add-log-exp6.2%
Applied egg-rr6.2%
Taylor expanded in x around inf 98.7%
if -1 < x < 0.94999999999999996Initial program 99.9%
Taylor expanded in x around 0 97.6%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -4000000000000.0) (not (<= z 5.5e+72))) (- x (* z (sin y))) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4000000000000.0) || !(z <= 5.5e+72)) {
tmp = x - (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 <= (-4000000000000.0d0)) .or. (.not. (z <= 5.5d+72))) then
tmp = x - (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 <= -4000000000000.0) || !(z <= 5.5e+72)) {
tmp = x - (z * Math.sin(y));
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4000000000000.0) or not (z <= 5.5e+72): tmp = x - (z * math.sin(y)) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4000000000000.0) || !(z <= 5.5e+72)) tmp = Float64(x - 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 <= -4000000000000.0) || ~((z <= 5.5e+72))) tmp = x - (z * sin(y)); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4000000000000.0], N[Not[LessEqual[z, 5.5e+72]], $MachinePrecision]], N[(x - 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 -4000000000000 \lor \neg \left(z \leq 5.5 \cdot 10^{+72}\right):\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -4e12 or 5.5e72 < z Initial program 99.8%
add-log-exp56.7%
Applied egg-rr56.7%
Taylor expanded in x around inf 93.0%
if -4e12 < z < 5.5e72Initial program 100.0%
Taylor expanded in z around 0 97.6%
+-commutative97.6%
Simplified97.6%
Final simplification95.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e+121) (not (<= z 6e+114))) (* z (- (sin y))) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+121) || !(z <= 6e+114)) {
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 <= (-2.4d+121)) .or. (.not. (z <= 6d+114))) 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 <= -2.4e+121) || !(z <= 6e+114)) {
tmp = z * -Math.sin(y);
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.4e+121) or not (z <= 6e+114): tmp = z * -math.sin(y) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e+121) || !(z <= 6e+114)) 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 <= -2.4e+121) || ~((z <= 6e+114))) tmp = z * -sin(y); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e+121], N[Not[LessEqual[z, 6e+114]], $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 -2.4 \cdot 10^{+121} \lor \neg \left(z \leq 6 \cdot 10^{+114}\right):\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -2.4e121 or 6.0000000000000001e114 < z Initial program 99.8%
Taylor expanded in z around inf 76.8%
associate-*r*76.8%
neg-mul-176.8%
*-commutative76.8%
Simplified76.8%
if -2.4e121 < z < 6.0000000000000001e114Initial program 100.0%
Taylor expanded in z around 0 90.6%
+-commutative90.6%
Simplified90.6%
Final simplification86.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.88) (not (<= y 1.15e-10))) (+ x (cos y)) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.88) || !(y <= 1.15e-10)) {
tmp = x + cos(y);
} else {
tmp = x + (1.0 - (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.88d0)) .or. (.not. (y <= 1.15d-10))) then
tmp = x + cos(y)
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.88) || !(y <= 1.15e-10)) {
tmp = x + Math.cos(y);
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.88) or not (y <= 1.15e-10): tmp = x + math.cos(y) else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.88) || !(y <= 1.15e-10)) tmp = Float64(x + cos(y)); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.88) || ~((y <= 1.15e-10))) tmp = x + cos(y); else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.88], N[Not[LessEqual[y, 1.15e-10]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.88 \lor \neg \left(y \leq 1.15 \cdot 10^{-10}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -0.880000000000000004 or 1.15000000000000004e-10 < y Initial program 99.8%
Taylor expanded in z around 0 56.4%
+-commutative56.4%
Simplified56.4%
if -0.880000000000000004 < y < 1.15000000000000004e-10Initial program 100.0%
Taylor expanded in y around 0 99.3%
associate-+r+99.3%
+-commutative99.3%
associate-+l+99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.5e+55) (not (<= y 0.015))) (+ x 1.0) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e+55) || !(y <= 0.015)) {
tmp = x + 1.0;
} else {
tmp = x + (1.0 - (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 <= (-4.5d+55)) .or. (.not. (y <= 0.015d0))) then
tmp = x + 1.0d0
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e+55) || !(y <= 0.015)) {
tmp = x + 1.0;
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.5e+55) or not (y <= 0.015): tmp = x + 1.0 else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.5e+55) || !(y <= 0.015)) tmp = Float64(x + 1.0); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.5e+55) || ~((y <= 0.015))) tmp = x + 1.0; else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.5e+55], N[Not[LessEqual[y, 0.015]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+55} \lor \neg \left(y \leq 0.015\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -4.49999999999999998e55 or 0.014999999999999999 < y Initial program 99.8%
Taylor expanded in y around 0 31.4%
+-commutative31.4%
Simplified31.4%
if -4.49999999999999998e55 < y < 0.014999999999999999Initial program 100.0%
Taylor expanded in y around 0 93.3%
associate-+r+93.3%
+-commutative93.3%
associate-+l+93.3%
mul-1-neg93.3%
unsub-neg93.3%
Simplified93.3%
Final simplification66.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-15) (not (<= x 9.8e-9))) (+ x 1.0) (- 1.0 (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-15) || !(x <= 9.8e-9)) {
tmp = x + 1.0;
} else {
tmp = 1.0 - (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 ((x <= (-6d-15)) .or. (.not. (x <= 9.8d-9))) then
tmp = x + 1.0d0
else
tmp = 1.0d0 - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-15) || !(x <= 9.8e-9)) {
tmp = x + 1.0;
} else {
tmp = 1.0 - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-15) or not (x <= 9.8e-9): tmp = x + 1.0 else: tmp = 1.0 - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-15) || !(x <= 9.8e-9)) tmp = Float64(x + 1.0); else tmp = Float64(1.0 - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e-15) || ~((x <= 9.8e-9))) tmp = x + 1.0; else tmp = 1.0 - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-15], N[Not[LessEqual[x, 9.8e-9]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-15} \lor \neg \left(x \leq 9.8 \cdot 10^{-9}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;1 - y \cdot z\\
\end{array}
\end{array}
if x < -6e-15 or 9.80000000000000007e-9 < x Initial program 99.9%
Taylor expanded in y around 0 77.9%
+-commutative77.9%
Simplified77.9%
if -6e-15 < x < 9.80000000000000007e-9Initial program 99.9%
add-log-exp99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around 0 50.6%
mul-1-neg50.6%
unsub-neg50.6%
Simplified50.6%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (<= z -6.5e+223) (* y (- z)) (+ x 1.0)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.5e+223) {
tmp = 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 (z <= (-6.5d+223)) then
tmp = 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 (z <= -6.5e+223) {
tmp = y * -z;
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.5e+223: tmp = y * -z else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.5e+223) tmp = Float64(y * Float64(-z)); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.5e+223) tmp = y * -z; else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.5e+223], N[(y * (-z)), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+223}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if z < -6.5000000000000001e223Initial program 99.7%
Taylor expanded in z around inf 88.4%
associate-*r*88.4%
neg-mul-188.4%
*-commutative88.4%
Simplified88.4%
Taylor expanded in y around 0 35.4%
mul-1-neg35.4%
distribute-rgt-neg-in35.4%
Simplified35.4%
if -6.5000000000000001e223 < z Initial program 99.9%
Taylor expanded in y around 0 61.6%
+-commutative61.6%
Simplified61.6%
Final simplification59.5%
(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 57.7%
+-commutative57.7%
Simplified57.7%
Final simplification57.7%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf 39.6%
Final simplification39.6%
herbie shell --seed 2023320
(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))))