
(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 (sin y) (- z) (+ x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x + cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x + cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x + \cos y\right)
\end{array}
Initial program 99.9%
sub-neg99.9%
+-commutative99.9%
*-commutative99.9%
distribute-rgt-neg-in99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x + cos(y)) - (sin(y) * z);
}
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)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x + math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - \sin y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -25000000000.0) (not (<= z 3e-12))) (- (- x -1.0) (* (sin y) z)) (+ x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -25000000000.0) || !(z <= 3e-12)) {
tmp = (x - -1.0) - (sin(y) * z);
} 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 <= (-25000000000.0d0)) .or. (.not. (z <= 3d-12))) then
tmp = (x - (-1.0d0)) - (sin(y) * z)
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 <= -25000000000.0) || !(z <= 3e-12)) {
tmp = (x - -1.0) - (Math.sin(y) * z);
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -25000000000.0) or not (z <= 3e-12): tmp = (x - -1.0) - (math.sin(y) * z) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -25000000000.0) || !(z <= 3e-12)) tmp = Float64(Float64(x - -1.0) - Float64(sin(y) * z)); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -25000000000.0) || ~((z <= 3e-12))) tmp = (x - -1.0) - (sin(y) * z); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -25000000000.0], N[Not[LessEqual[z, 3e-12]], $MachinePrecision]], N[(N[(x - -1.0), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -25000000000 \lor \neg \left(z \leq 3 \cdot 10^{-12}\right):\\
\;\;\;\;\left(x - -1\right) - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if z < -2.5e10 or 3.0000000000000001e-12 < z Initial program 99.9%
flip-+79.0%
div-inv79.0%
fma-neg79.0%
pow279.0%
pow279.0%
*-commutative79.0%
distribute-rgt-neg-in79.0%
Applied egg-rr79.0%
fma-udef79.0%
*-commutative79.0%
cancel-sign-sub-inv79.0%
associate-*r/79.0%
*-rgt-identity79.0%
Simplified79.0%
Taylor expanded in y around 0 78.9%
unpow278.9%
fma-neg78.9%
metadata-eval78.9%
sub-neg78.9%
metadata-eval78.9%
Simplified78.9%
metadata-eval78.9%
fma-neg78.9%
metadata-eval78.9%
flip--99.7%
Applied egg-rr99.7%
if -2.5e10 < z < 3.0000000000000001e-12Initial program 100.0%
Taylor expanded in z around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= x -3.7e+27)
x
(if (<= x -6.8e-129)
(+ x (- 1.0 (* y z)))
(if (<= x 6.2e-10) (cos y) (+ x 1.0)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.7e+27) {
tmp = x;
} else if (x <= -6.8e-129) {
tmp = x + (1.0 - (y * z));
} else if (x <= 6.2e-10) {
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.7d+27)) then
tmp = x
else if (x <= (-6.8d-129)) then
tmp = x + (1.0d0 - (y * z))
else if (x <= 6.2d-10) 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.7e+27) {
tmp = x;
} else if (x <= -6.8e-129) {
tmp = x + (1.0 - (y * z));
} else if (x <= 6.2e-10) {
tmp = Math.cos(y);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.7e+27: tmp = x elif x <= -6.8e-129: tmp = x + (1.0 - (y * z)) elif x <= 6.2e-10: tmp = math.cos(y) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.7e+27) tmp = x; elseif (x <= -6.8e-129) tmp = Float64(x + Float64(1.0 - Float64(y * z))); elseif (x <= 6.2e-10) 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.7e+27) tmp = x; elseif (x <= -6.8e-129) tmp = x + (1.0 - (y * z)); elseif (x <= 6.2e-10) tmp = cos(y); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.7e+27], x, If[LessEqual[x, -6.8e-129], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.2e-10], N[Cos[y], $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{+27}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -6.8 \cdot 10^{-129}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-10}:\\
\;\;\;\;\cos y\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -3.70000000000000002e27Initial program 100.0%
Taylor expanded in x around inf 90.3%
if -3.70000000000000002e27 < x < -6.80000000000000026e-129Initial program 99.8%
Taylor expanded in y around 0 67.3%
associate-+r+67.3%
+-commutative67.3%
associate-+l+67.3%
mul-1-neg67.3%
unsub-neg67.3%
Simplified67.3%
if -6.80000000000000026e-129 < x < 6.2000000000000003e-10Initial program 99.9%
add-sqr-sqrt80.1%
pow280.1%
associate--l+80.1%
Applied egg-rr80.1%
Taylor expanded in x around 0 80.1%
Taylor expanded in z around 0 71.8%
if 6.2000000000000003e-10 < x Initial program 100.0%
Taylor expanded in y around 0 89.5%
+-commutative89.5%
Simplified89.5%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0034) (not (<= y 6.4e-35))) (+ x (cos y)) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0034) || !(y <= 6.4e-35)) {
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.0034d0)) .or. (.not. (y <= 6.4d-35))) 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.0034) || !(y <= 6.4e-35)) {
tmp = x + Math.cos(y);
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0034) or not (y <= 6.4e-35): 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.0034) || !(y <= 6.4e-35)) 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.0034) || ~((y <= 6.4e-35))) 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.0034], N[Not[LessEqual[y, 6.4e-35]], $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.0034 \lor \neg \left(y \leq 6.4 \cdot 10^{-35}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -0.00339999999999999981 or 6.3999999999999996e-35 < y Initial program 99.9%
Taylor expanded in z around 0 72.4%
+-commutative72.4%
Simplified72.4%
if -0.00339999999999999981 < y < 6.3999999999999996e-35Initial program 100.0%
Taylor expanded in y around 0 100.0%
associate-+r+100.0%
+-commutative100.0%
associate-+l+100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.6e+98) (not (<= y 1.45e+29))) (+ x 1.0) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.6e+98) || !(y <= 1.45e+29)) {
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 <= (-7.6d+98)) .or. (.not. (y <= 1.45d+29))) 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 <= -7.6e+98) || !(y <= 1.45e+29)) {
tmp = x + 1.0;
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.6e+98) or not (y <= 1.45e+29): tmp = x + 1.0 else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.6e+98) || !(y <= 1.45e+29)) 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 <= -7.6e+98) || ~((y <= 1.45e+29))) tmp = x + 1.0; else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.6e+98], N[Not[LessEqual[y, 1.45e+29]], $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 -7.6 \cdot 10^{+98} \lor \neg \left(y \leq 1.45 \cdot 10^{+29}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -7.5999999999999998e98 or 1.45e29 < y Initial program 99.9%
Taylor expanded in y around 0 47.3%
+-commutative47.3%
Simplified47.3%
if -7.5999999999999998e98 < y < 1.45e29Initial program 100.0%
Taylor expanded in y around 0 92.8%
associate-+r+92.8%
+-commutative92.8%
associate-+l+92.8%
mul-1-neg92.8%
unsub-neg92.8%
Simplified92.8%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e-7) (not (<= x 1.45e-12))) (+ x 1.0) (- 1.0 (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e-7) || !(x <= 1.45e-12)) {
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 <= (-3.9d-7)) .or. (.not. (x <= 1.45d-12))) 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 <= -3.9e-7) || !(x <= 1.45e-12)) {
tmp = x + 1.0;
} else {
tmp = 1.0 - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e-7) or not (x <= 1.45e-12): tmp = x + 1.0 else: tmp = 1.0 - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e-7) || !(x <= 1.45e-12)) 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 <= -3.9e-7) || ~((x <= 1.45e-12))) tmp = x + 1.0; else tmp = 1.0 - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e-7], N[Not[LessEqual[x, 1.45e-12]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{-7} \lor \neg \left(x \leq 1.45 \cdot 10^{-12}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;1 - y \cdot z\\
\end{array}
\end{array}
if x < -3.90000000000000025e-7 or 1.4500000000000001e-12 < x Initial program 100.0%
Taylor expanded in y around 0 88.4%
+-commutative88.4%
Simplified88.4%
if -3.90000000000000025e-7 < x < 1.4500000000000001e-12Initial program 99.9%
Taylor expanded in y around 0 57.7%
associate-+r+57.7%
+-commutative57.7%
associate-+l+57.7%
mul-1-neg57.7%
unsub-neg57.7%
Simplified57.7%
Taylor expanded in x around 0 57.6%
Final simplification74.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.0) x (if (<= x 1.45) 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x;
} else if (x <= 1.45) {
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 <= (-1.0d0)) then
tmp = x
else if (x <= 1.45d0) 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 <= -1.0) {
tmp = x;
} else if (x <= 1.45) {
tmp = 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = x elif x <= 1.45: tmp = 1.0 else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = x; elseif (x <= 1.45) tmp = 1.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.0) tmp = x; elseif (x <= 1.45) tmp = 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], x, If[LessEqual[x, 1.45], 1.0, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.45:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 1.44999999999999996 < x Initial program 100.0%
Taylor expanded in x around inf 88.4%
if -1 < x < 1.44999999999999996Initial program 99.9%
add-sqr-sqrt76.9%
pow276.9%
associate--l+76.9%
Applied egg-rr76.9%
Taylor expanded in x around 0 74.4%
Taylor expanded in y around 0 45.1%
Final simplification67.6%
(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 68.9%
+-commutative68.9%
Simplified68.9%
Final simplification68.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%
add-sqr-sqrt61.8%
pow261.8%
associate--l+61.8%
Applied egg-rr61.8%
Taylor expanded in x around 0 38.7%
Taylor expanded in y around 0 23.4%
Final simplification23.4%
herbie shell --seed 2024019
(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))))