
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (+ x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x + 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 = (z * cos(y)) + (x + sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x + Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x + math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x + sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x + sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + \left(x + \sin y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -8e+17)
t_0
(if (<= z 1.15e-65) (+ x (sin y)) (if (<= z 1.5e+85) (+ x z) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -8e+17) {
tmp = t_0;
} else if (z <= 1.15e-65) {
tmp = x + sin(y);
} else if (z <= 1.5e+85) {
tmp = x + z;
} else {
tmp = 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 * cos(y)
if (z <= (-8d+17)) then
tmp = t_0
else if (z <= 1.15d-65) then
tmp = x + sin(y)
else if (z <= 1.5d+85) then
tmp = x + z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -8e+17) {
tmp = t_0;
} else if (z <= 1.15e-65) {
tmp = x + Math.sin(y);
} else if (z <= 1.5e+85) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -8e+17: tmp = t_0 elif z <= 1.15e-65: tmp = x + math.sin(y) elif z <= 1.5e+85: tmp = x + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -8e+17) tmp = t_0; elseif (z <= 1.15e-65) tmp = Float64(x + sin(y)); elseif (z <= 1.5e+85) tmp = Float64(x + z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -8e+17) tmp = t_0; elseif (z <= 1.15e-65) tmp = x + sin(y); elseif (z <= 1.5e+85) tmp = x + z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -8e+17], t$95$0, If[LessEqual[z, 1.15e-65], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.5e+85], N[(x + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -8 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-65}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+85}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8e17 or 1.5e85 < z Initial program 99.8%
Taylor expanded in z around inf 81.6%
if -8e17 < z < 1.15e-65Initial program 100.0%
Taylor expanded in z around 0 96.4%
+-commutative96.4%
Simplified96.4%
if 1.15e-65 < z < 1.5e85Initial program 99.8%
Taylor expanded in y around 0 78.8%
+-commutative78.8%
Simplified78.8%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e-53) (not (<= z 5.4e-68))) (+ x (* z (cos y))) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-53) || !(z <= 5.4e-68)) {
tmp = x + (z * cos(y));
} else {
tmp = x + sin(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 <= (-1.15d-53)) .or. (.not. (z <= 5.4d-68))) then
tmp = x + (z * cos(y))
else
tmp = x + sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-53) || !(z <= 5.4e-68)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e-53) or not (z <= 5.4e-68): tmp = x + (z * math.cos(y)) else: tmp = x + math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e-53) || !(z <= 5.4e-68)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(x + sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.15e-53) || ~((z <= 5.4e-68))) tmp = x + (z * cos(y)); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e-53], N[Not[LessEqual[z, 5.4e-68]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-53} \lor \neg \left(z \leq 5.4 \cdot 10^{-68}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -1.1500000000000001e-53 or 5.4000000000000003e-68 < z Initial program 99.9%
Taylor expanded in x around inf 97.9%
if -1.1500000000000001e-53 < z < 5.4000000000000003e-68Initial program 100.0%
Taylor expanded in z around 0 97.9%
+-commutative97.9%
Simplified97.9%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.05e-82) (not (<= x 9.5e-50))) (+ x z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e-82) || !(x <= 9.5e-50)) {
tmp = x + z;
} else {
tmp = z * 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 <= (-2.05d-82)) .or. (.not. (x <= 9.5d-50))) then
tmp = x + z
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e-82) || !(x <= 9.5e-50)) {
tmp = x + z;
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.05e-82) or not (x <= 9.5e-50): tmp = x + z else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.05e-82) || !(x <= 9.5e-50)) tmp = Float64(x + z); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.05e-82) || ~((x <= 9.5e-50))) tmp = x + z; else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.05e-82], N[Not[LessEqual[x, 9.5e-50]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-82} \lor \neg \left(x \leq 9.5 \cdot 10^{-50}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -2.04999999999999998e-82 or 9.4999999999999993e-50 < x Initial program 99.9%
Taylor expanded in y around 0 83.0%
+-commutative83.0%
Simplified83.0%
if -2.04999999999999998e-82 < x < 9.4999999999999993e-50Initial program 99.9%
Taylor expanded in z around inf 62.1%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.5e-95) (not (<= x 1.06e-9))) (+ x z) (+ z (+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-95) || !(x <= 1.06e-9)) {
tmp = x + z;
} else {
tmp = z + (x + 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.5d-95)) .or. (.not. (x <= 1.06d-9))) then
tmp = x + z
else
tmp = z + (x + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-95) || !(x <= 1.06e-9)) {
tmp = x + z;
} else {
tmp = z + (x + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.5e-95) or not (x <= 1.06e-9): tmp = x + z else: tmp = z + (x + y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.5e-95) || !(x <= 1.06e-9)) tmp = Float64(x + z); else tmp = Float64(z + Float64(x + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.5e-95) || ~((x <= 1.06e-9))) tmp = x + z; else tmp = z + (x + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.5e-95], N[Not[LessEqual[x, 1.06e-9]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-95} \lor \neg \left(x \leq 1.06 \cdot 10^{-9}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + y\right)\\
\end{array}
\end{array}
if x < -3.4999999999999997e-95 or 1.0600000000000001e-9 < x Initial program 99.9%
Taylor expanded in y around 0 83.1%
+-commutative83.1%
Simplified83.1%
if -3.4999999999999997e-95 < x < 1.0600000000000001e-9Initial program 99.9%
Taylor expanded in y around 0 58.4%
+-commutative58.4%
+-commutative58.4%
associate-+l+58.4%
Simplified58.4%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (<= x -19000000000.0) x (if (<= x 1.85e-6) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -19000000000.0) {
tmp = x;
} else if (x <= 1.85e-6) {
tmp = z;
} 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 <= (-19000000000.0d0)) then
tmp = x
else if (x <= 1.85d-6) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -19000000000.0) {
tmp = x;
} else if (x <= 1.85e-6) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -19000000000.0: tmp = x elif x <= 1.85e-6: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -19000000000.0) tmp = x; elseif (x <= 1.85e-6) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -19000000000.0) tmp = x; elseif (x <= 1.85e-6) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -19000000000.0], x, If[LessEqual[x, 1.85e-6], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -19000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.85 \cdot 10^{-6}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.9e10 or 1.8500000000000001e-6 < x Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.8%
associate-*l*99.8%
fma-define99.8%
pow299.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 77.1%
if -1.9e10 < x < 1.8500000000000001e-6Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.5%
associate-*l*99.4%
fma-define99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in z around inf 60.2%
*-commutative60.2%
Simplified60.2%
Taylor expanded in y around 0 40.7%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 67.5%
+-commutative67.5%
Simplified67.5%
Final simplification67.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%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.6%
associate-*l*99.6%
fma-define99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 42.4%
herbie shell --seed 2024094
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))