
(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 8 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 (+ x (cos y)))) (if (or (<= y -15.8) (not (<= y 4.15e+58))) t_0 (- t_0 (* y z)))))
double code(double x, double y, double z) {
double t_0 = x + cos(y);
double tmp;
if ((y <= -15.8) || !(y <= 4.15e+58)) {
tmp = t_0;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = x + cos(y)
if ((y <= (-15.8d0)) .or. (.not. (y <= 4.15d+58))) then
tmp = t_0
else
tmp = t_0 - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + Math.cos(y);
double tmp;
if ((y <= -15.8) || !(y <= 4.15e+58)) {
tmp = t_0;
} else {
tmp = t_0 - (y * z);
}
return tmp;
}
def code(x, y, z): t_0 = x + math.cos(y) tmp = 0 if (y <= -15.8) or not (y <= 4.15e+58): tmp = t_0 else: tmp = t_0 - (y * z) return tmp
function code(x, y, z) t_0 = Float64(x + cos(y)) tmp = 0.0 if ((y <= -15.8) || !(y <= 4.15e+58)) tmp = t_0; else tmp = Float64(t_0 - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + cos(y); tmp = 0.0; if ((y <= -15.8) || ~((y <= 4.15e+58))) tmp = t_0; else tmp = t_0 - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[y, -15.8], N[Not[LessEqual[y, 4.15e+58]], $MachinePrecision]], t$95$0, N[(t$95$0 - N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \cos y\\
\mathbf{if}\;y \leq -15.8 \lor \neg \left(y \leq 4.15 \cdot 10^{+58}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 - y \cdot z\\
\end{array}
\end{array}
if y < -15.800000000000001 or 4.1499999999999998e58 < y Initial program 99.9%
add-log-exp99.6%
Applied egg-rr99.6%
add-cube-cbrt99.1%
pow399.1%
log-pow99.2%
pow1/399.2%
log-pow99.6%
add-log-exp99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 41.4%
*-commutative41.4%
Simplified41.4%
Taylor expanded in z around 0 67.3%
+-commutative67.3%
Simplified67.3%
if -15.800000000000001 < y < 4.1499999999999998e58Initial program 100.0%
Taylor expanded in y around 0 96.5%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00045) (not (<= y 0.0004))) (+ x (cos y)) (+ 1.0 (+ (- x (* y z)) (* -0.5 (* y y))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00045) || !(y <= 0.0004)) {
tmp = x + cos(y);
} else {
tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * 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.00045d0)) .or. (.not. (y <= 0.0004d0))) then
tmp = x + cos(y)
else
tmp = 1.0d0 + ((x - (y * z)) + ((-0.5d0) * (y * y)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00045) || !(y <= 0.0004)) {
tmp = x + Math.cos(y);
} else {
tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * y)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00045) or not (y <= 0.0004): tmp = x + math.cos(y) else: tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * y))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00045) || !(y <= 0.0004)) tmp = Float64(x + cos(y)); else tmp = Float64(1.0 + Float64(Float64(x - Float64(y * z)) + Float64(-0.5 * Float64(y * y)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00045) || ~((y <= 0.0004))) tmp = x + cos(y); else tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * y))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00045], N[Not[LessEqual[y, 0.0004]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00045 \lor \neg \left(y \leq 0.0004\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \left(\left(x - y \cdot z\right) + -0.5 \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -4.4999999999999999e-4 or 4.00000000000000019e-4 < y Initial program 99.9%
add-log-exp99.6%
Applied egg-rr99.6%
add-cube-cbrt99.0%
pow399.0%
log-pow99.1%
pow1/399.2%
log-pow99.6%
add-log-exp99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 43.2%
*-commutative43.2%
Simplified43.2%
Taylor expanded in z around 0 66.7%
+-commutative66.7%
Simplified66.7%
if -4.4999999999999999e-4 < y < 4.00000000000000019e-4Initial program 100.0%
add-log-exp83.7%
Applied egg-rr83.7%
add-cube-cbrt83.7%
pow383.7%
log-pow83.7%
pow1/383.7%
log-pow83.7%
add-log-exp99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in y around 0 99.9%
mul-1-neg99.9%
distribute-rgt-neg-out99.9%
associate-+r+99.9%
distribute-rgt-neg-out99.9%
sub-neg99.9%
unpow299.9%
Simplified99.9%
Final simplification83.4%
(FPCore (x y z)
:precision binary64
(if (<= y -4.8)
(+ x 1.0)
(if (<= y 58000000000000.0)
(+ 1.0 (+ (- x (* y z)) (* -0.5 (* y y))))
(+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8) {
tmp = x + 1.0;
} else if (y <= 58000000000000.0) {
tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * 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 <= (-4.8d0)) then
tmp = x + 1.0d0
else if (y <= 58000000000000.0d0) then
tmp = 1.0d0 + ((x - (y * z)) + ((-0.5d0) * (y * 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 <= -4.8) {
tmp = x + 1.0;
} else if (y <= 58000000000000.0) {
tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * y)));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8: tmp = x + 1.0 elif y <= 58000000000000.0: tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * y))) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8) tmp = Float64(x + 1.0); elseif (y <= 58000000000000.0) tmp = Float64(1.0 + Float64(Float64(x - Float64(y * z)) + Float64(-0.5 * Float64(y * y)))); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.8) tmp = x + 1.0; elseif (y <= 58000000000000.0) tmp = 1.0 + ((x - (y * z)) + (-0.5 * (y * y))); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 58000000000000.0], N[(1.0 + N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 58000000000000:\\
\;\;\;\;1 + \left(\left(x - y \cdot z\right) + -0.5 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -4.79999999999999982 or 5.8e13 < y Initial program 99.9%
add-log-exp99.6%
Applied egg-rr99.6%
add-cube-cbrt99.0%
pow399.0%
log-pow99.0%
pow1/399.2%
log-pow99.6%
add-log-exp99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 42.3%
*-commutative42.3%
Simplified42.3%
Taylor expanded in y around 0 37.5%
+-commutative37.5%
Simplified37.5%
if -4.79999999999999982 < y < 5.8e13Initial program 100.0%
add-log-exp84.0%
Applied egg-rr84.0%
add-cube-cbrt83.9%
pow383.9%
log-pow84.0%
pow1/384.0%
log-pow84.0%
add-log-exp99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in y around 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
associate-+r+99.8%
distribute-rgt-neg-out99.8%
sub-neg99.8%
unpow299.8%
Simplified99.8%
Final simplification69.4%
(FPCore (x y z) :precision binary64 (if (<= y -8.4e+33) (+ x 1.0) (if (<= y 3.1e+180) (+ 1.0 (- x (* y z))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e+33) {
tmp = x + 1.0;
} else if (y <= 3.1e+180) {
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 <= (-8.4d+33)) then
tmp = x + 1.0d0
else if (y <= 3.1d+180) 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 <= -8.4e+33) {
tmp = x + 1.0;
} else if (y <= 3.1e+180) {
tmp = 1.0 + (x - (y * z));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.4e+33: tmp = x + 1.0 elif y <= 3.1e+180: tmp = 1.0 + (x - (y * z)) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.4e+33) tmp = Float64(x + 1.0); elseif (y <= 3.1e+180) 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 <= -8.4e+33) tmp = x + 1.0; elseif (y <= 3.1e+180) tmp = 1.0 + (x - (y * z)); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.4e+33], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 3.1e+180], 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 -8.4 \cdot 10^{+33}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+180}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -8.4000000000000002e33 or 3.09999999999999998e180 < y Initial program 99.9%
add-log-exp99.6%
Applied egg-rr99.6%
add-cube-cbrt99.1%
pow399.1%
log-pow99.1%
pow1/399.2%
log-pow99.6%
add-log-exp99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 32.3%
*-commutative32.3%
Simplified32.3%
Taylor expanded in y around 0 39.2%
+-commutative39.2%
Simplified39.2%
if -8.4000000000000002e33 < y < 3.09999999999999998e180Initial program 100.0%
add-log-exp87.5%
Applied egg-rr87.5%
add-cube-cbrt87.4%
pow387.4%
log-pow87.4%
pow1/387.4%
log-pow87.5%
add-log-exp99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 91.6%
*-commutative91.6%
Simplified91.6%
Taylor expanded in y around 0 84.2%
mul-1-neg84.2%
sub-neg84.2%
Simplified84.2%
Final simplification69.1%
(FPCore (x y z) :precision binary64 (if (<= z -1e+222) (* y (- z)) (+ x 1.0)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e+222) {
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 <= (-1d+222)) 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 <= -1e+222) {
tmp = y * -z;
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e+222: tmp = y * -z else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e+222) 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 <= -1e+222) tmp = y * -z; else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e+222], N[(y * (-z)), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+222}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if z < -1e222Initial program 99.9%
add-log-exp46.3%
Applied egg-rr46.3%
add-cube-cbrt45.4%
pow345.5%
log-pow45.7%
pow1/345.8%
log-pow46.2%
add-log-exp99.2%
Applied egg-rr99.2%
Taylor expanded in y around 0 71.3%
*-commutative71.3%
Simplified71.3%
Taylor expanded in y around inf 58.6%
mul-1-neg58.6%
distribute-rgt-neg-out58.6%
Simplified58.6%
if -1e222 < z Initial program 99.9%
add-log-exp94.2%
Applied egg-rr94.2%
add-cube-cbrt94.0%
pow393.9%
log-pow94.0%
pow1/394.0%
log-pow94.2%
add-log-exp99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 71.7%
*-commutative71.7%
Simplified71.7%
Taylor expanded in y around 0 63.2%
+-commutative63.2%
Simplified63.2%
Final simplification62.9%
(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%
add-log-exp91.6%
Applied egg-rr91.6%
add-cube-cbrt91.3%
pow391.3%
log-pow91.3%
pow1/391.4%
log-pow91.6%
add-log-exp99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 71.7%
*-commutative71.7%
Simplified71.7%
Taylor expanded in y around 0 60.5%
+-commutative60.5%
Simplified60.5%
Final simplification60.5%
(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%
add-log-exp91.6%
Applied egg-rr91.6%
add-cube-cbrt91.3%
pow391.3%
log-pow91.3%
pow1/391.4%
log-pow91.6%
add-log-exp99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 71.7%
*-commutative71.7%
Simplified71.7%
Taylor expanded in x around inf 43.7%
Final simplification43.7%
herbie shell --seed 2023275
(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))))