
(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 8 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 96.8%
*-commutative96.8%
sub-neg96.8%
distribute-rgt-in96.9%
metadata-eval96.9%
neg-mul-196.9%
associate-+r+96.9%
unsub-neg96.9%
+-commutative96.9%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.3e+234)
(* x y)
(if (<= x -1.0)
(* x z)
(if (<= x 2.4e-108) (- z) (if (<= x 2.7e+41) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+234) {
tmp = x * y;
} else if (x <= -1.0) {
tmp = x * z;
} else if (x <= 2.4e-108) {
tmp = -z;
} else if (x <= 2.7e+41) {
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.3d+234)) then
tmp = x * y
else if (x <= (-1.0d0)) then
tmp = x * z
else if (x <= 2.4d-108) then
tmp = -z
else if (x <= 2.7d+41) 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.3e+234) {
tmp = x * y;
} else if (x <= -1.0) {
tmp = x * z;
} else if (x <= 2.4e-108) {
tmp = -z;
} else if (x <= 2.7e+41) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e+234: tmp = x * y elif x <= -1.0: tmp = x * z elif x <= 2.4e-108: tmp = -z elif x <= 2.7e+41: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+234) tmp = Float64(x * y); elseif (x <= -1.0) tmp = Float64(x * z); elseif (x <= 2.4e-108) tmp = Float64(-z); elseif (x <= 2.7e+41) 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.3e+234) tmp = x * y; elseif (x <= -1.0) tmp = x * z; elseif (x <= 2.4e-108) tmp = -z; elseif (x <= 2.7e+41) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+234], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.4e-108], (-z), If[LessEqual[x, 2.7e+41], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+234}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-108}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+41}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.30000000000000008e234 or 2.40000000000000017e-108 < x < 2.7e41Initial program 92.6%
Taylor expanded in y around inf 65.9%
if -1.30000000000000008e234 < x < -1 or 2.7e41 < x Initial program 95.6%
*-commutative95.6%
sub-neg95.6%
distribute-rgt-in95.6%
metadata-eval95.6%
neg-mul-195.6%
associate-+r+95.6%
unsub-neg95.6%
+-commutative95.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 68.4%
Taylor expanded in x around inf 68.4%
*-commutative68.4%
Simplified68.4%
if -1 < x < 2.40000000000000017e-108Initial program 100.0%
Taylor expanded in x around inf 76.4%
+-commutative76.4%
mul-1-neg76.4%
unsub-neg76.4%
Simplified76.4%
Taylor expanded in x around 0 65.1%
neg-mul-165.1%
Simplified65.1%
Final simplification66.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.0115))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.0115)) {
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.0115d0))) 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.0115)) {
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.0115): 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.0115)) 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.0115))) 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.0115]], $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.0115\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1 or 0.0115 < x Initial program 93.4%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
Simplified99.2%
if -1 < x < 0.0115Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 98.2%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.7e+110) (not (<= y 1.85e-40))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e+110) || !(y <= 1.85e-40)) {
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 ((y <= (-2.7d+110)) .or. (.not. (y <= 1.85d-40))) 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 ((y <= -2.7e+110) || !(y <= 1.85e-40)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.7e+110) or not (y <= 1.85e-40): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.7e+110) || !(y <= 1.85e-40)) 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 ((y <= -2.7e+110) || ~((y <= 1.85e-40))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.7e+110], N[Not[LessEqual[y, 1.85e-40]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+110} \lor \neg \left(y \leq 1.85 \cdot 10^{-40}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -2.7000000000000001e110 or 1.84999999999999999e-40 < y Initial program 93.2%
Taylor expanded in x around inf 83.9%
+-commutative83.9%
Simplified83.9%
if -2.7000000000000001e110 < y < 1.84999999999999999e-40Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 87.0%
Taylor expanded in z around 0 87.0%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.6e-36) (not (<= x 9.5e-37))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6e-36) || !(x <= 9.5e-37)) {
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 <= (-8.6d-36)) .or. (.not. (x <= 9.5d-37))) 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 <= -8.6e-36) || !(x <= 9.5e-37)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.6e-36) or not (x <= 9.5e-37): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.6e-36) || !(x <= 9.5e-37)) 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 <= -8.6e-36) || ~((x <= 9.5e-37))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.6e-36], N[Not[LessEqual[x, 9.5e-37]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-36} \lor \neg \left(x \leq 9.5 \cdot 10^{-37}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.6000000000000004e-36 or 9.49999999999999927e-37 < x Initial program 94.1%
Taylor expanded in x around inf 95.2%
+-commutative95.2%
Simplified95.2%
if -8.6000000000000004e-36 < x < 9.49999999999999927e-37Initial program 100.0%
Taylor expanded in x around inf 77.4%
+-commutative77.4%
mul-1-neg77.4%
unsub-neg77.4%
Simplified77.4%
Taylor expanded in x around 0 65.7%
neg-mul-165.7%
Simplified65.7%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.4e-31) (not (<= y 3.6e-41))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e-31) || !(y <= 3.6e-41)) {
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 ((y <= (-1.4d-31)) .or. (.not. (y <= 3.6d-41))) 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 ((y <= -1.4e-31) || !(y <= 3.6e-41)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4e-31) or not (y <= 3.6e-41): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.4e-31) || !(y <= 3.6e-41)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.4e-31) || ~((y <= 3.6e-41))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4e-31], N[Not[LessEqual[y, 3.6e-41]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-31} \lor \neg \left(y \leq 3.6 \cdot 10^{-41}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.3999999999999999e-31 or 3.6e-41 < y Initial program 94.2%
Taylor expanded in y around inf 69.1%
if -1.3999999999999999e-31 < y < 3.6e-41Initial program 99.9%
Taylor expanded in x around inf 89.6%
+-commutative89.6%
mul-1-neg89.6%
unsub-neg89.6%
Simplified89.6%
Taylor expanded in x around 0 49.0%
neg-mul-149.0%
Simplified49.0%
Final simplification59.9%
(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 96.8%
Taylor expanded in x around inf 89.4%
+-commutative89.4%
mul-1-neg89.4%
unsub-neg89.4%
Simplified89.4%
Taylor expanded in x around 0 33.8%
neg-mul-133.8%
Simplified33.8%
(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 z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 96.8%
Taylor expanded in x around inf 89.4%
+-commutative89.4%
mul-1-neg89.4%
unsub-neg89.4%
Simplified89.4%
Taylor expanded in x around 0 33.8%
neg-mul-133.8%
Simplified33.8%
neg-sub033.8%
sub-neg33.8%
add-sqr-sqrt18.0%
sqrt-unprod19.7%
sqr-neg19.7%
sqrt-unprod1.4%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
+-lft-identity2.7%
Simplified2.7%
herbie shell --seed 2024145
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))