
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.0) (* x z) (if (<= x 0.00065) (- z) (if (<= x 1.9e+235) (* x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= 0.00065) {
tmp = -z;
} else if (x <= 1.9e+235) {
tmp = x * y;
} else {
tmp = x * 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 <= (-1.0d0)) then
tmp = x * z
else if (x <= 0.00065d0) then
tmp = -z
else if (x <= 1.9d+235) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = x * z;
} else if (x <= 0.00065) {
tmp = -z;
} else if (x <= 1.9e+235) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = x * z elif x <= 0.00065: tmp = -z elif x <= 1.9e+235: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * z); elseif (x <= 0.00065) tmp = Float64(-z); elseif (x <= 1.9e+235) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.0) tmp = x * z; elseif (x <= 0.00065) tmp = -z; elseif (x <= 1.9e+235) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 0.00065], (-z), If[LessEqual[x, 1.9e+235], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 0.00065:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+235}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1 or 1.89999999999999988e235 < x Initial program 95.9%
Taylor expanded in y around 0 60.0%
Taylor expanded in x around inf 58.2%
*-commutative58.2%
Simplified58.2%
if -1 < x < 6.4999999999999997e-4Initial program 100.0%
Taylor expanded in x around 0 74.2%
neg-mul-174.2%
Simplified74.2%
if 6.4999999999999997e-4 < x < 1.89999999999999988e235Initial program 96.4%
Taylor expanded in y around inf 61.4%
Final simplification66.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.0024))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.0024)) {
tmp = x * (z + y);
} else {
tmp = (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 ((x <= (-1.0d0)) .or. (.not. (x <= 0.0024d0))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.0024)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 0.0024): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.0024)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.0024))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.0024]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.0024\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1 or 0.00239999999999999979 < x Initial program 96.1%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -1 < x < 0.00239999999999999979Initial program 100.0%
Taylor expanded in y around inf 82.8%
Taylor expanded in x around 0 81.6%
associate-*r/81.6%
neg-mul-181.6%
Simplified81.6%
Taylor expanded in y around 0 98.6%
+-commutative98.6%
fma-define98.6%
mul-1-neg98.6%
fma-neg98.6%
Simplified98.6%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -32000.0) (not (<= x 0.0022))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -32000.0) || !(x <= 0.0022)) {
tmp = x * (z + y);
} else {
tmp = z * (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 <= (-32000.0d0)) .or. (.not. (x <= 0.0022d0))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -32000.0) || !(x <= 0.0022)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -32000.0) or not (x <= 0.0022): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -32000.0) || !(x <= 0.0022)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -32000.0) || ~((x <= 0.0022))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -32000.0], N[Not[LessEqual[x, 0.0022]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -32000 \lor \neg \left(x \leq 0.0022\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -32000 or 0.00220000000000000013 < x Initial program 96.1%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
Simplified99.2%
if -32000 < x < 0.00220000000000000013Initial program 100.0%
Taylor expanded in y around 0 75.9%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e-35) (not (<= x 0.00065))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-35) || !(x <= 0.00065)) {
tmp = x * (z + y);
} else {
tmp = -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.6d-35)) .or. (.not. (x <= 0.00065d0))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-35) || !(x <= 0.00065)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e-35) or not (x <= 0.00065): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e-35) || !(x <= 0.00065)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.6e-35) || ~((x <= 0.00065))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e-35], N[Not[LessEqual[x, 0.00065]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-35} \lor \neg \left(x \leq 0.00065\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.60000000000000019e-35 or 6.4999999999999997e-4 < x Initial program 96.4%
Taylor expanded in x around inf 95.1%
+-commutative95.1%
Simplified95.1%
if -3.60000000000000019e-35 < x < 6.4999999999999997e-4Initial program 100.0%
Taylor expanded in x around 0 76.6%
neg-mul-176.6%
Simplified76.6%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-36) (not (<= x 0.00065))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-36) || !(x <= 0.00065)) {
tmp = x * y;
} else {
tmp = -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 <= (-5.8d-36)) .or. (.not. (x <= 0.00065d0))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-36) || !(x <= 0.00065)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-36) or not (x <= 0.00065): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-36) || !(x <= 0.00065)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-36) || ~((x <= 0.00065))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-36], N[Not[LessEqual[x, 0.00065]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-36} \lor \neg \left(x \leq 0.00065\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.80000000000000026e-36 or 6.4999999999999997e-4 < x Initial program 96.4%
Taylor expanded in y around inf 54.2%
if -5.80000000000000026e-36 < x < 6.4999999999999997e-4Initial program 100.0%
Taylor expanded in x around 0 76.6%
neg-mul-176.6%
Simplified76.6%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 38.0%
neg-mul-138.0%
Simplified38.0%
herbie shell --seed 2024087
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))