
(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 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -3.6e+217)
(* x z)
(if (<= x -1.95e-16)
(* x y)
(if (<= x 1.0) (- z) (if (<= x 1.55e+220) (* x z) (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e+217) {
tmp = x * z;
} else if (x <= -1.95e-16) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 1.55e+220) {
tmp = x * z;
} else {
tmp = 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.6d+217)) then
tmp = x * z
else if (x <= (-1.95d-16)) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = -z
else if (x <= 1.55d+220) then
tmp = x * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e+217) {
tmp = x * z;
} else if (x <= -1.95e-16) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 1.55e+220) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.6e+217: tmp = x * z elif x <= -1.95e-16: tmp = x * y elif x <= 1.0: tmp = -z elif x <= 1.55e+220: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.6e+217) tmp = Float64(x * z); elseif (x <= -1.95e-16) tmp = Float64(x * y); elseif (x <= 1.0) tmp = Float64(-z); elseif (x <= 1.55e+220) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.6e+217) tmp = x * z; elseif (x <= -1.95e-16) tmp = x * y; elseif (x <= 1.0) tmp = -z; elseif (x <= 1.55e+220) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.6e+217], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.95e-16], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], (-z), If[LessEqual[x, 1.55e+220], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+217}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.95 \cdot 10^{-16}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{+220}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.6000000000000002e217 or 1 < x < 1.55e220Initial program 96.8%
*-commutative96.8%
sub-neg96.8%
distribute-rgt-in96.8%
metadata-eval96.8%
neg-mul-196.8%
associate-+r+96.8%
unsub-neg96.8%
+-commutative96.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 66.2%
Taylor expanded in x around inf 65.0%
*-commutative65.0%
Simplified65.0%
if -3.6000000000000002e217 < x < -1.94999999999999989e-16 or 1.55e220 < x Initial program 98.6%
Taylor expanded in y around inf 61.5%
if -1.94999999999999989e-16 < x < 1Initial 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 99.1%
Taylor expanded in x around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification69.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 97.8%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -1 < x < 1Initial 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 99.1%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.36e-16) (not (<= x 750.0))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.36e-16) || !(x <= 750.0)) {
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 <= (-1.36d-16)) .or. (.not. (x <= 750.0d0))) 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 <= -1.36e-16) || !(x <= 750.0)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.36e-16) or not (x <= 750.0): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.36e-16) || !(x <= 750.0)) 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 <= -1.36e-16) || ~((x <= 750.0))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.36e-16], N[Not[LessEqual[x, 750.0]], $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 -1.36 \cdot 10^{-16} \lor \neg \left(x \leq 750\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -1.3599999999999999e-16 or 750 < x Initial program 97.8%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -1.3599999999999999e-16 < x < 750Initial 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 78.2%
Taylor expanded in z around 0 78.2%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e-16) (not (<= x 0.8))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e-16) || !(x <= 0.8)) {
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.9d-16)) .or. (.not. (x <= 0.8d0))) 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.9e-16) || !(x <= 0.8)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e-16) or not (x <= 0.8): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e-16) || !(x <= 0.8)) 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.9e-16) || ~((x <= 0.8))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e-16], N[Not[LessEqual[x, 0.8]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{-16} \lor \neg \left(x \leq 0.8\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.89999999999999977e-16 or 0.80000000000000004 < x Initial program 97.8%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -3.89999999999999977e-16 < x < 0.80000000000000004Initial 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 99.1%
Taylor expanded in x around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.85e-16) (not (<= x 0.8))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.85e-16) || !(x <= 0.8)) {
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 <= (-1.85d-16)) .or. (.not. (x <= 0.8d0))) 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 <= -1.85e-16) || !(x <= 0.8)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.85e-16) or not (x <= 0.8): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.85e-16) || !(x <= 0.8)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.85e-16) || ~((x <= 0.8))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.85e-16], N[Not[LessEqual[x, 0.8]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-16} \lor \neg \left(x \leq 0.8\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.85e-16 or 0.80000000000000004 < x Initial program 97.8%
Taylor expanded in y around inf 52.8%
if -1.85e-16 < x < 0.80000000000000004Initial 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 99.1%
Taylor expanded in x around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification64.2%
(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.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 74.8%
Taylor expanded in x around 0 37.9%
neg-mul-137.9%
Simplified37.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 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.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 74.8%
Taylor expanded in x around 0 37.9%
neg-mul-137.9%
Simplified37.9%
neg-sub037.9%
sub-neg37.9%
add-sqr-sqrt19.4%
sqrt-unprod17.6%
sqr-neg17.6%
sqrt-unprod1.2%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
+-lft-identity2.5%
Simplified2.5%
herbie shell --seed 2024138
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))